Publish WordPress Widget On Certain Pages Only

November 11, 2011 10:43 am

When you install a WordPress plugin and create a widget, it would be published on all pages of your website. Have you ever wondered how to publish some WordPress widgets on certain pages only? WordPress core does not allow users to select pages where a widget would be published. Instead, it publishes it on all the pages.

widget control

We have found a nice plugin that gives us this useful feature. Its name is Widget Context and we intensively used it on almost all our WordPress themes so far. If we had a big image or news rotator widget on the home page that occupies a lot of space (which is OK for the home page), it would be odd to have the same widget on all the pages throughout the site.

After the successful installation and activation of the Widget Control plugin, you would have a new box under the usual widget options box. It will become a part of all the widgets installed on your WordPress site. This is where you control the widget’s availability on your website pages. There are several methods to determine what pages to publish the widget. We will explain here some of the most useful methods. As an example, we will study our WordPress travel theme. In this theme, we have Hot Designation plugin, and we would like to publish it on the home page only. On the Widgets page of the WordPress dashboard, the Hot Designation plugin has been published in the User2 widget sidebar. When we click on its name, we can see the plugin’s options. Under the plugin’s options, there’s also the Widget Control plugin. If you don’t edit any option in the Widget Control, the widget will be published on all pages throughout the site.

How to publish the widget only on certain pages? First of all, we should select pages where to publish (or hide) the widget (they are published on all pages by default). The first criterion for page selection is by page type (front page, blog index, single post, single page, attachment, search, all archives, category archive, tag archive, author archive or 404 error). All those page types are presented as checkboxes. Another criterion is by the number of words on-page. In gives you the ability to select pages that have fewer or more words than the number you entered. There’s also a text box where you can select pages by URL (one rule per line). Simply enter page URL, in example */test and to select page yoursite.com/test. In this text box, you can use wildcards, in example category/news/* to target all news category posts, or 2011/* to match articles written in the year 2011.

After you finished the pages selection, you should determine whether to show or hide the widget on the selected pages. Make your selection in the Widget visibility selector.

After activation, the Widget Control’s options become a part of other’s widget options. Therefore, when you save the widget’s options, you would save your selection of pages where to show or hide the widget.