Support » Plugin: Widget Logic » [Plugin: Widget Logic] Use $widget_ID ?

  • I am trying to target a specific widget to append a “all news” link below it’s list of recent news posts, titles only.

    $widget_id is mentioned in the Other Notes for Widget Logic and it seems to be the perfect solution. However, there is no example regarding what to DO with the $widget_id variable within a function.

    so far I have:

    function all_news_link($content='', $widget_id'){
    return $content;

    I simply want to modify this so that the div with “TEST” in it will only show up on this specific widget with the ID=”query-posts-3″

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Contributor alanft


    it’s a filter function – air gets the HTML to output ($content) and (in this case) the widget ID. all you have to do is modify the $content and return it. a bit like the code at the end of

    something like

    return $content.”<div>TEST</div>”;

    will give you the right idea

    alanft –

    My “Test” content shows up just fine. BUT it shows in ALL widgets. So, what I don’t understand is how the function knows what the $widget_id variable is.

    Hows does $widget_id get a value (presumably the widget ID “query-posts-3”) assigned to it?

    I’ve played with this for days now with only the ability to append text to every widget I’m using. That is why I’m here asking for assistance. I do not know how to get the plugin/function to ONLY apply the text “TEST” to the one widget I’m targeting.

    The $widget_id is a string value that represents the CSS style ID for the LI that contains the widget (i.e., <li id="text-3">widget stuff</li>
    … in this case, $widget_id = “text-3”). It’s not a value to change, but a value that changes based on the particular widget being dealt with by WP at a given moment. A good example to see it in action is to set up 2-3 widgets in a test site, and place the following in your functions.php file:

    add_filter('widget_content', 'my_widget_function', 90, 2);
    function my_widget_function( $content='', $widget_id='') {
        return $content . '<p>This widget\'s style ID = ' . $widget_id . '</p>';

    So, as you will see, each widget will contain whatever content is already in it AND at the end of each widget’s content will be “This widget’s style ID = <current widget ID>”.


    Plugin Contributor alanft


    @squidz, you have to change your function. first off get rid of the text that outputs the TEST text every time it’s called


    and instead get it to RETURN the text you want, e.g.

    return $content."ID=".$widget_id;

    which will instead put the widget_id at the end of the widget content. Then you can alter it to have conditional changes to what it returns.

    We worked it out and have it under control now Alan. But it took a bunch of trial and error.

    Widget Logic isone of the most useful plugins around and this particular feature can quite powerful too. To allow people that aren’t full-on developers to exploit it, including a clear and straightforward example of how to use the feature on Widget Logic’s “Other Notes” page would be a wonderful thing.

    Plugin Contributor alanft


    i’ve added a tiny bit extra text in the documentation (not yet updated on that should give people the nudge needed.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘[Plugin: Widget Logic] Use $widget_ID ?’ is closed to new replies.