How to make WordPress widgets show only on selected pages and posts

By January 14, 2010 Wordpress 20 Comments

Have you ever wanted a WordPress widget to show only on one page or post? It's extremely useful to be able to limit widgets based on where a visitor is in your blog. Not only does it help you preserve and manage your valuable screen real estate, but it also helps you organize information for your website visitors.

A good example of how this might work is by limiting ads to relevant pages. Let's say you have a banner ad that you'd like to display to promote a product, but you only want that ad to show on one post. By default, WordPress widgets don't provide a way for you to limit where they are shown. After a widget is placed in the sidebar, it's just there. You can move it up or down, but it's still going to be displayed across the entire site.

Using a few simple plug-ins, you can not only control where widgets appear, but you can also rotate ads in those spots. Below is a video that walks you through the process of adding two widgets to your WordPress blog. Those two widgets are DataFeedr Random Ads and Widget Logic. Watch the video above to see how these two plug-ins help you to control where you're ads display and how much ad space you can get from a single ad spot.

UPDATED: Thanks to Jenny over at Wholistic Health Solutions for pointing out that is_page( array( 1, 2, 3 ) ) can be used to include more than one page or post in the Widget Logic conditional code. The array ( 1, 2, 3 ) portion of the WordPress conditional code is meant to act as a list of pages / posts that apply to the widget's rules.

If you know of another way to do the same thing, leave a comment and let me know.

Charles McKeever
Open Source Marketer

About Charles McKeever

Charles McKeever is the founder of Open Source Marketer, an online marketing and mobile, web development company that helps business owners design, build, and market their businesses' online. Connect with him on one of your favorite social channels.

Want web or mobile development help? Contact Us