Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #580
    Jenna Fava
    Participant

    Hi. I am trying to restrict a widget to a specific post and it shows me the post as an option under the show/hide menu and I select it but it doesn’t work. I can specify a specific category but not to a specific post. Can you tell me what I am doing wrong? I assumed if its showing me the option, it would work when I select it.

    #594
    Bartosz
    Keymaster

    You can achieve that, but not with an option.

    All you need is to take advantage of the rw_display_widget filter, like this:

    function custom_rw_display_widget ($display, $instance) {
    if (is_single(1) && $instance['title'] == 'Your widget title') { // change Your widget title
    $display = true; // or false if you want to hide it
    }
    return $display;
    }
    add_filter('rw_display_widget', 'custom_rw_display_widget', 10, 2);

    This will display a widget with title “Your widget title” if post ID is equal to 1. Just add this to your theme’s functions.php and adjust to your needs. You may use literally any combination of conditional tags described in the codex http://codex.wordpress.org/Conditional_Tags

    Hope this helps

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.