WordPress.org

Forums

[resolved] Best way to link a widget to theme content and site pages? (3 posts)

  1. Opally
    Member
    Posted 2 years ago #

    I want to have some relative links and theme images display in widgets. The sidebars show up at different levels of the URL, so an ordinary relative link won't always work. What's the right way to do this? No relative links? I'm working on a development/sandbox site that has a different site root structure from the production site.

    Normally on a template one uses the WP hooks site_url() and get_stylesheet_directory_uri() for things like this, but I can't put those in text widgets.

    I have experimented with Shortcode Exec PHP plugin, but it seems a bit of overkill, and doesn't work quite right when packing two shortcodes into one widget; the second shortcode doesn't get evaluated until executed in a link, so the second link when hovered displays the shortcode.

    Do I need to write custom widgets for this? I'm looking at http://codex.wordpress.org/Widgets_API and suggested resources linked there.

    What I would like is for the customer to be able to edit a widget that has well formed links to the same site, and can access images that are in the theme.

    which just now makes me think that for the theme images, I should just put the image I wamt to use in the media gallery, and use its link.

    But this doesn't address the problem with on site links, apart from hard-coding the full URLs into the widgets. That may be the simplest thing, but it's not ideal.

    How should I be handling this?

  2. Opally
    Member
    Posted 2 years ago #

    I've been reading Sitepoint's "The WordPress Anthology" to get better informed about all of WP's features, and I just read about the shortcode API.

    What do you think about making custom shortcode functions instead of using the Shortcode Exec PHP plugin, which seems like a bit of overkill for just supporting relative links inside widgets?

    Or do you think I should create custom widgets for my customer's theme, so that the sidebars link correctly, no matter the depth of their URL?

    Or do you think one should simply hardcode the full URLs to links in ordinary text widgets?

    I would like to hear how developers recommend handling this.

  3. Opally
    Member
    Posted 2 years ago #

    I have learned from reading "The WordPress Anthology" published by SitePoint, that the best way to do this is by writing custom shortcodes. It was easy!

Topic Closed

This topic has been closed to new replies.

About this Topic