Feedback

13 Feb 2013

Add Hide Widgets On Certain Pages, Categories And Posts In WordPress

widget logic plugin for wordpressHow many of us want to hide or show widget on certain posts or categories or visitors coming from certain websites and its quite essential  to show up your affiliate ads or a poll based upon the a particular page or a category. I am not gonna write a code for these functions rather I found a pretty cool WordPress plugin named Widget Logic that adds the ability to hide or show widgets on your WordPress blog.
So this is not actually a tutorial, but a tip to add some logic to the widgets that are used on your WordPress blog. The functions of this plugin uses the WordPress conditional tags.
Once you have installed the plugin, you can see the Widget Logic text box added to all the widgets and now using the functions you can add conditional tag to hide or show the widgets on certain pages or categories or posts. If you are not much aware of WordPress conditional tags, you can have a look at it here
To make this post pretty helpful I have added some common tags that hides or shows widgets and here we go.
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 greet 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.
category ID in wordpressis_user_logged_in() to display the widget only for logged in users.
*To know category numbers in WordPress head to the category page in your Wp admin and click on edit on any of the one category. Look into your address bar to find the category ID.
If you are looking for more conditional tags drop in your comments.
 

People

My Photo
We are also on Facebook We are on Twitter Home Page
Hello friends i am Jaskaran SH SD from Amritsar (Punjab) India. I love blogging. First I started a blog on science in 2010. Now I handle only this blog. I like to share the things which I know. I learn many things through blogging. I always try to make different that's why I learn many things. 

About Blog

Construct Internet is one of dedicated source for Internet, Computer and technology tutorials and development. It is Started in Oct 21 2012. We provide a professional tools for websites and blogging, along with a wide range of tutorials, How to fix etc. for computers and other technology development. Social news, Business and Social Science like topics are also followed in our blog.

We 'r Social

2012-2013 Construct Internet. Copying Without Permission is Strictly Prohibited.