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

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.

WooThemes - Now for EE

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

Join the forum discussion on this post

Related posts:

Pocket Video Power

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

  • peter james kirkpatrick

    Excellent Post right what i was after and Explained like a pro and solved my problem Keep up your amazing work =) found you by typing into google: make word press widget appear only on home
    (just FYI) cheers

  • Thanks dude. you really help me solve my problem about widget arrangement at any pages

  • I like your article,
    I’ve recently started a blog, the information you provide on this site has helped me tremendously. Thank you for all …

  • Hi and thankyou! Just what I needed. I was trying out flexible widgets, but it only seemed to work when the widget didn’t have any options or input to add once dragged to the widget location.
    The widgets logic plugin solved the problem.

    Note: for multiple page selection for inclusion, the following line works is_page( array( 42, 54, 6 ) )
    not
    (not the line is_page(42,54,6) as appears in your tutorial

    • Thank you Jenny. I’m glad the Widget Logic plugin worked for you. We use it on all of our site and all of our client sites. I would imagine that this would eventually be rolled into WordPress. It just seems like a no-brainer feature.

      Yes, you are absolutely correct, is_page( array( 42, 54, 6 ) ) is the correct format. I will update the article to reflect this. For anyone who is new to WordPress or Widget Logic, Using the array allows you to include a list of pages / posts that should be covered in the plugin. It makes using WordPress conditional codes very simple.

      Leave me a link to your website where you used Widget Logic and I’ll be sure to include it in the the post as an example for everyone else.

  • Hi again,
    Yes agreed – one would think that this functionality would be a standard feature of WP.

    You can see the use Widget Logic at the Wholistic Health Solutions Development/Testing site at http://www.jerrys-ads.com/dev .
    The Wp Ultra Simple Paypal Shopping Car widget has been placed on selective pages –
    The product summary pagehttp://jerrys-ads.com/dev/products
    All product detail pages – (select items in drop down menu under product on main menu)…..note: scroll to the end of the page to see the shopping cart widget on product pages
    A dedicated shoping cart page http://jerrys-ads.com/dev/shopping-cart

    All other pages on the site do not diplay the shopping cart widget!

Leave a Reply

  

  

  

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>