How to Place WordPress Widgets Only on Certain Pages

By default, WordPress shows the same sidebar widgets on every page. If you need to hide widgets on certain pages, categories, post types, etc, you can use conditional tags.

In order to add conditional tags quickly and easily, you can use the Widget Logic plugin. Download it here: Widget Logic

This plugin adds an input field to every widget, where you can add the conditional tags.

In the example in the screenshot above, the Tag widget will only show on the post with ID 17.

If instead you would like to show the widget on all pages except the post with ID 17, you can put an ‘!’ at the start like this:

!is_single( '17' )

A list of all available conditional tags can be found on the WordPress codex site here.

How to add a new widget area to your WordPress theme

Most WordPress Themes come by default with some pre-defined areas where you can drop your widgets in. But often this is not enough and you need to add additional areas, for example for advertising space or other features.

This is how to do it:

First Step: Add widget Area to Theme
In the index.php file in your theme directory (/wp-content/themes/mytheme), add the following code in the area where you would like a new widget to appear. Note we have had to wrap this line of code so it displays. Careful of too many spaces.


Second Step: Function.php

Put this line at the end of the function.php file:

register_sidebar(array('name'=>'Post Widget',));

Third Step: Style

Now you can style the new widget area via stylesheet, example:

.widget_post {
	background: #FFFFFF;
	margin: 0px;
	padding: 10px;
	width: 600px;
	}

And then go to the WordPress backend and look in the widget section for the newly created area and drop in your desired widget. That’s it 🙂

x


Request a quote

I will get back to you within 24 hours.