WordPress Widget Logic: How to Display Different Widgets on Each Page

Wordpress Widget LogicRecently, 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.

About Brian Bourn

At the helm of Bourn Creative, is Brian, who manages the day-to-day business operations and all company projects. While he spends most days entrenched in code, Star Wars, WordPress, and the Genesis Framework building client websites and custom themes, Brian is also a brilliant business strategist and can often be found consulting with clients on how to best achieve their online goals.

Able to break down complicated topics into easy to understand, simple steps, Brian regularly attends and speaks at meetup groups, WordCamps (his favorite), networking events, and conferences on the topics of design, website strategy, and tech-nerd stuff.

Bourn Creative Recommends WP Engine

WP Engine WordPress Hosting Gain peace of mind knowing your website (the main source of your online income) is safe, secure, and protected with WP Engine - an insanely fast, infinitely scalable, backed up, secure, expert WordPress hosting company that’s got your back!

Comments & Feedback:

  1. Brian, Thanks so much for the tips on widgets. Although I am not super tech savvy, I now have you as a great resource!! Love your Bourn Creative work!!

  2. I can see that there’s so many creative ideas I hadn’t thought about (and suspect I don’t have the techie skills to master). Thank heaven for folks like you, Brian!

  3. Thanks Jennifer! I use WP for both of my blogs. Now I see that I’ve got some homework to study!

  4. Great tip, but not something I’ll do myself, LOL! I was searching for just such a solution not long ago, I’ll let my techie person know. Thanks!

  5. Just when I think WordPress can’t get any cooler, you introduce me to a nifty new widget. I love this idea. Guess what I’ll be doing this week:)

  6. Thanks Jennifer. It’s a pleasure to meet you. It appears we have a lot in common starting with our love of WordPress! Thanks so much for the widget tips.

  7. 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 says:

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

  8. Definitely something I’ll use in the future …

  9. 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.

  10. I am having some trouble getting Widget Logic to work completely on my site (http://hinterlandgazette.com). 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.

  11. Thank you very much! It works for my blog

  12. 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.

      • Hi Brian,

        Thank you for referring us to Widget Logic.

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

        On this site -newtechnology.co.in/iphone-5-price-in-india/ , 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 Comments & Feedback: