• Hi,

    I have four custom widget area in the footer and accordingly I have added 4 widgets to each of the widget areas.

    In one of the widgets (sidebar-2) I have two widgets. I wish to display one of the two (sidebar-2) in my blog page and keep it hidden from rest of the site. How to execute this using php conditional tags.

    I tried this one but did not work

    <?php if(! is_active_sidebar( 'sidebar-2' ) && is_page(2831) )
    <div id="recent-posts-2">
    <?php endif; ?>
Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    is_active_sidebar() only tells you if a sidebar has widgets attached, not if it is the sidebar being output. You also have a syntax error, there is no closing ?> before the HTML portion. Your error log should be showing a ‘Unexpected “<“‘ type error. The error log is always a good clue to find out where something went wrong. Define WP_DEBUG as true in wp-config.php to see errors in your browser instead of having to get the error log.

    You could use dynamic sidebar filters to wrap the entire widget area in a particular div class only when a particular page is loaded. Set up the widget CSS to by default display: none;. Then when the widget is inside that particular div class, set the CSS to display: block;.

    Or you could remove the particular widget from the sidebar in general. Then edit the sidebar template to only load the widget if the query is for a particular page. Use the_widget() to load a specific widget that is not part of the dynamic sidebar.

Viewing 1 replies (of 1 total)
  • The topic ‘Hide a particular widget on a page’ is closed to new replies.