Update: I prepared a 39 minutes long detailed video on using the widget logic plugin with various conditonal tags.
Show or Display WordPress Widgets wherever you like:
I didn’t know what existed in WordPress for my needs when it comes to display or hide widgets in specific (certain) pages, posts, category pages, archive pages etc. Accidentally, I came to know that there was a plugin named ‘widget logic’ to help me.
Installing the plugin is not hard. It installs just in few seconds as we would normally install any WP plugins. After installation, just go to the “widgets” under the “appearances” tab on your WordPress dashboard.
Look on each widget and there you can see a box named “Widget Logic”. You have to write the conditional tags in that box to hide or display the widget in specific (certain) pages.
So getting most out of this plugin depends upon how much we know about conditional tags. IF you are newbie to the phrase “conditional tags“, then do not worry about that. It is very little piece of code that could do bigger things. To show how easy it is to understand the conditional tags, here is an example. is_page()
Display the Widget
This is_page() conditional tag can be used while we want to display or hide widgets in wordpress pages.
Now I explain you how to use this conditional tag in Widget Logic plugin. If you want to display the widget in just wordpress single pages only and not in posts, home page, categories etc, then what we have to do is, just paste the code is_page() in the “Widget Logic” box under the corresponding widget.
But in another case, if you just want to display the widget only in a specific (certain) page, for example, if you want to display the widget in “Advertise with us” page alone, then the code we will have to use is_single(‘5’) where ‘5’ is page id of the “advertise” page. [Here is the tutorial to find Post Id and Page Id in WordPress dashboard]
Now if you want to display the widget in more than one specific (certain) page, then the code we will have to use is_page(array(5,6)). You may use the page titles instead of the page ids. The code for this is_page(‘Advertise with us’) where “Advertise with us” is the title of advertise page.
You may also use the slug of the page instead page id, title then the code is is_page(‘advertise-with-us’) where the advertise-with-us is the slug of the page.
Hide the Widget
If you want to hide the widget in all pages, the code we will have to use is !is_page(). Note the symbol ‘!’ in the code which denotes ‘not to display’ in that case.
By this way you may use these codes !is_page(‘5’), !is_page(array(4,5)), !is_page(‘Advertise with us’) etc, where you want to hide the widget in page which has id 5, in pages 4 & 5 , in page titled “Advertise with us” respectively.
Below are the few of the wordpress conditional tags for your needs.
is_page() – Already explained this in above example.
is_single() – This is for WordPress Posts.
is_category() – This is for Category archive pages.
is_tag() – This is for tag archive pages.
is_date() – This is for daily, monthly, yearly archive pages
is_archive() – This is for all category, tag, day, monthly, yearly archive pages.
is_home() – This is for home page only. If you have selected a static page as the blog front page at Settings -> Reading, then the is_home() page will not work to display the widget.
In that static front page. In this case, it will work at the page selected as “posts” page at Settings -> Reading.
is_front_page() – front page of the blog
is_sticky() – if a post selected as the sticky post
comments_open() – if comments are allowed
pings_open() – if pings are allowed
is_author() – if author archive displayed
is_search() – if search results page displayed
is_404() – if 404 page shown
is_active_sidebar() – if sidebar in active,
is_plugin_active() – if a plugin is active
is_singular – At all of these cases is_single(), is_page(), is_attachment()
If are new to WordPress, here is the Ultimate Guide to create website with WordPress