How to: Create Custom Sidebars with Widget Logic

Published on July 19th, 2011

Last Updated on May 8th, 2019


Share This Article

With the addition of custom menus in WordPress, it has become much easier to define your own menus. However, it still does not give the ability to make entirely custom sidebars. There are some of you out there who would prefer to have complete control over all of your sidebars and where specific widgets will be shown.The Widget Logic plugin essentially gives every widget a new field where you can specify where it should appear. You may want to have a custom sidebar on every single page on your WordPress blog, and Widget Logic is just the right tool to achieve this.

Install Widget Logic

The plugin is available to download on the WordPress plugins directory. You could also install the plugin from your WordPress website. There is virtually nothing to configure at all. You just install and activate and you are ready to go.

Using Widget Logic

Widget Logic may seem a little confusing at first, however you just need to get yourself acquainted with WordPress’ conditional tags. They are essentially quite simple to understand.

Let’s say you have three pages: Home, About and Contact. If you would like a widget to simply appear on the homepage only, you would need to visit the widget configuration page on your WordPress website and open the widget to display it’s settings. A logic field will now viewable and you will be able to enter a conditional tag to choose where to display this widget. To display this widget purely on the homepage, you would enter the following:


As you can see, it is fairly simple to define where your specific widgets will be shown. However, if you would like to display this widget on a page other than the homepage, you would need to know the Page ID of that particular page. To find the out a Page ID, go to your page list on your WordPress blog and hover over a page. You will be shown the links destination and at the end of the link, you can see the ID of that specific page.

Once you have acquired the specific Page ID’s that you need, you will need to implement them in to the following code:


I have used the Page ID’s one, three and five for this example. The above code means that only those three pages will be shown on that pages relative sidebar.

Advanced Logic

There are several other tags that can be used within the logic field that can be classed as somewhat advanced, such as:

Article Continues Below

This tag will make this widget only viewable to administrators only :


This widget is only viewable to those who have reached the page through a google search :

[php]strpos($_SERVER[‘HTTP_REFERER’], "")!=false[/php]

This widget will appear for posts tagged with “featured” :

[php]has_tag (‘featured’)[/php]

For all posts in the “WordPress” category :


You can find more advanced widget codes on the plugin author’s website. I hope you found this guide useful, tell us if you find this plugin useful!

A team of WordPress experts that love to test out new WordPress related software, WordPress plugins and WordPress themes.