Widget Logic is a powerful plugin that controls where a widget should appear and conversely where it should not. This is a great lightweight plugin so I have it installed on all my blogs. It is included on my list of first plugins to install on a site running WordPress. After you install the plugin a new input area will be added below each of your widgets. That’s where we’ll put our WordPress Conditional tags and other statements.
Note: Widget Logic is powerful and flexible but if you’re having a hard time understanding logical statements in PHP and want for a simpler and more user-friendly solution then check out Widget Options.
How to Use WordPress Conditional Tags
Here are more Conditional Tags that are useful for determining widget placement
is_front_page() Show widget on the front page.
is_home() Show widget on the “posts page” aka “blog page”.
is_page() Show widget on pages. You can use the Page’s ID, Title or Slug.
is_page( array('About', 'Contact', 50, 75) )
is_single() Show widget on posts.
is_single( array('Hello World', 'Happy Birthday Post', 45) )
in_category() Show widget if post is in a category.
in_category( array('Anime', 'Manga', 'Cat1', 'Cat2') )
has_tag() Show widget if post has a tag.
has_tag( array('Tutorials', 'WordPress', 'Tag1', 'Tag2') )
get_post_type() == 'topic' Show widget if a bbPress Topic is being displayed. You can also use
is_bbpress() but this will produce an error if the bbPress plugin is not installed or disabled. I was originally trying to find a way to use
function_exists() in Widget Logic to wrap on
is_bbpress() but I haven’t had any success.
You can also use
get_post_type() when specific post types are in use.
Other Tips on Using Widget Logic
- Combining statements allows you to have more control.
(!)adds some flexibility and is sometimes more efficient.
- If you have AdSense ads on your widgets you might want to add this condition.
Show widget on Home page and the About page.
is_front_page() || is_page('About')
Show widget on pages with a Tutorial Tag and on bbPress Topics.
has_tag('Tutorial') || ( get_post_type() == 'topic' )
Show the widget everywhere but not on the Home page.
Show the widget on all posts but not on Pages.
Show the widget everywhere but not on the About page.
This prevents the ads from showing whenever we click Preview on the Post Editor. This is done so that Google Bots won’t crawl the preview page and consequently report the page as missing or status 404.