Sometimes we have to hide or show widgets on certain Pages, Posts or Categories to show up different content, affiliate ads or a poll on a particular page or a category. This can be achieved via using WordPress Conditional Tags, but I found excellent WordPress plugins for doing the same job: Named Widget Logic and Widget Context that had the ability to hide or show widgets on your WordPress blog pages and posts.
1. Widget Logic
Widget Logic lets you control the widgets visibility. It uses WP’s conditional tags to control the appearance of Widgets on desired pages/templates. It also adds a ‘widget_content’ filter.
- The ‘Widget logic’ field at work in standard widgets.
wp_reset_queryoptions are at the foot of the widget admin page. (Both are off by default.)
Here are some common tags explained that hides or shows widgets on WordPress Posts and Pages:
- is_single() to display the widget only on single pages is_home() to display the widget only on home page
- is_single(12) to display the widget on the post ID 12. The post ID is nothing but a unique number that was allocated to a blog post. So how to find the post? Simple one of my fellow blogger have blogged about it, just head over there.
- !is_home() to display the widget on all the places except the homepage.
- strpos($_SERVER[‘HTTP_REFERER’], “google.com”)!=false to display the widget for visitors who comes through Google. You can try the same step to replace Google.com with Facebook.com if you want to have a greetings message for Facebook users.
- is_single(‘Blogger Tips’) to display the widget on the post titled Blogger Tips. This indirectly helps you in adding a suitable affiliates ads for certain pages.
- is_page(‘contact’) to display the widget only on a particular page contact. You can change the value “contact” to any page name of your wish.
- is_category(array(5,9,10,11)) to display the widget only for certain category classified by category numbers*. You can even use single category numbers to hide or show widgets.
- is_user_logged_in() to display the widget only for logged in users.
Show widgets in context – only on certain posts, front page, category or tag pages etc. Widget Context allows you to specify widget visibility settings.
Hope, this post caters your need of Widget visibility on certain WordPress Pages. Please let me know in comments if there is any other option available.