standard icon

Control Your Widgets: How to Display Different Widgets on Each Page

Recently, a client with a custom WordPress site we built wanted to display different text in a single sidebar widget on each top level page so when a visitor clicked through the navigation, the sidebar content in that one particular widget would change. This can be accomplished in many ways, but one solution is through the use of the WordPress plug-in Widget Logic.

The plugin gives every widget an extra field where you can use WordPress’ conditional tags to control what page(s) your widgets appear on.

For example:

  • You want a widget only to appear on your about page but not any others
  • You want a video in the sidebar to auto play on the home page, but not on any other page
  • You want a different testimonial to show up in the testimonial widget on each page
  • You want to offer different opt-in offers on different website pages
  • You want to display a specific widget only on posts by a certain author or in a specific category

With Widget Logic, you can drag a new widget into your sidebar, add the conditional tag is_page( ‘about’ ), and the widget you just created will only appear on the about page.

For this example, you would need to create a different widget for each page and assign each widget to each page using a conditional tag. I would use the WordPress page ID conditional tag is_page( ’45’ ) changing the number for each widget to match the actual page ID you want the widget to appear on. Through the use of WordPress’ conditional tags you can also specify unique widgets at a broader scale such as pages, posts, templates, authors, categories, tags, etc.

As a reminder, before installing and testing a new plugin that you are unfamiliar with, completely back-up your WordPress files and database in case your theme isn’t compatible.

Subscribe To Our Blog & Never Miss A Thing

Sign up to get new our latest posts and announcements delivered straight to your inbox. Seriously, at this point, what’s one more email?

Comments & Feedback:Check out what others have to say about this post!

  1. Thanks for the widget info. I have a wordpress site with widgets on my side bar that allow for different testimonials on different pages. I’m wondering if it’s the same plug in or something else. I have some things on my sidebar that need to be updated. Thank goodness for tech savvy folks like you!

    • Jennifer Bourn

      Tiffany – there are thousands of plug-ins available and we test out a lot of them – this one is one of our favorites though!

  2. Tomas

    Thanks for the info.
    Doesn’t work with on my site though.

    I have set: is_page(‘5’) for a widget that I only want to display on the page that ends in “post.php?post=5&action=edit”
    5 IS the pages number, no?
    Any idea why it doesn’t work?

    • Tomas, your code looks like it might be a little off. Try is_page( 5 ). Note the spaces and the no quotes around the page ID. Take a look at the Codex page I have linked to in the article for all of the conditional tags you can use and their proper syntax.

  3. I am having some trouble getting Widget Logic to work completely on my site ( I have a customer who wants to run his ads only on the Crime and Justice section of my site. I got the code to work with in the header widget box:

    is_category(‘crime-and-justice’) || (is_single() && in_category(‘crime-and-justice’))

    I have a second widget box in the header to run all Adsense ads on other sections and I used:

    ‘is_category(‘crime-and-justice’) || (is_single() && in_category(‘crime-and-justice’))

    When I go back to the site and click on the individual posts in Crime and Justice, the Adsense ads pop up and not the customer’s ad. What did I do wrong?

    I moved my blog from Blogger to WordPress and used the customer URL permalink (/%year%/%monthnum%/%postname%.html). Not sure if that’s the problem.

    Please help, I’m about to lose a customer.

    • I think your conditional syntax is a little off and that may be what is not working for you. If you go back to the WordPress Codex you should see that in_category uses the category id and not the slug.

      Also, you may want to check the “reset query” checkbox on your widgets page that Widget Logic adds. Some themes have issues using this plugin and that can sometimes resolve them.

  4. Was wondering how to set a unique widget for every post/page and this plugin, Widget Logic, seems to be an excellent resolution. So great work Brian, really appreciate your insight!

    • If you need add unique content for every page or post outside the WordPress post editor, a widget and this plugin would not be a good solution. For something like this, using custom fields or custom meta boxes would probably be best.

      • Ankur

        Hi Brian,

        Thank you for referring us to Widget Logic.

        I got a good query which I thought of asking you –

        On this site , you’ll notice a price comparison chart on the right side of every product review post. And with a different product review, the values for the product changes on the right side bar.

        Can we do it too with the help of widget logic? Basically I am starting a product-review site and would love to put up the amount/value for that product from different e-commerce stores on my sidebar.

        Currently, I am using tablepress but it’s of no use as long as the sidebar is ‘global’ (regardless of posts).

        What could be a possible solution for this?

        • Your use case would probably not be a good use of Widget Logic. It sounds like you will need to create custom code to retrieve the data dynamically based on the product.

Share Your Thoughts & Opinions!

Have something to say, add, or share? Speak up!