How to use Widget Logic for WordPress

Widget Logic is a powerful plugin that controls where a widget should appear and conversely where it should not. This is a great lightweight plugin so I have it installed on all my blogs. It is included on my list of first plugins to install on a site running WordPress. After you install the plugin a new input area will be added below each of your widgets. That’s where we’ll put our WordPress Conditional tags and other statements.

In this sample, the Text Widget will only appear if the blog page or posts page is being displayed.

How to Use WordPress Conditional Tags

Here are more Conditional Tags that are useful for determining widget placement

is_front_page() Show widget on the front page.

is_home() Show widget on the “posts page” aka “blog page”.

is_page() Show widget on pages. You can use the Page’s ID, Title or Slug.

    is_page( array('About', 'Contact', 50, 75) )

is_single() Show widget on posts.
    is_single('Hello World')
    is_single( array('Hello World', 'Happy Birthday Post', 45) )

in_category() Show widget if post is in a category.
    in_category( array('Anime', 'Manga', 'Cat1', 'Cat2') )

has_tag() Show widget if post has a tag.
    has_tag( array('Tutorials', 'WordPress', 'Tag1', 'Tag2') )

get_post_type() == 'topic' Show widget if a bbPress Topic is being displayed. You can also use is_bbpress() but this will produce an error if the bbPress plugin is not installed or disabled. I was originally trying to find a way to use function_exists() in Widget Logic to wrap on is_bbpress() but I haven’t had any success.

You can also use get_post_type() when specific post types are in use.

Other Tips on Using Widget Logic

  • Combining statements allows you to have more control.
  • Example:
    Show widget on Home page and the About page.
    is_front_page() || is_page('About')

    Show widget on pages with a Tutorial Tag and on bbPress Topics.
    has_tag('Tutorial') || ( get_post_type() == 'topic' )

  • Negation (!) adds some flexibility and is sometimes more efficient.
  • Example:
    Show the widget everywhere but not on the Home page.

    Show the widget on all posts but not on Pages.

    Show the widget everywhere but not on the About page.

  • If you have AdSense ads on your widgets you might want to add this condition.
  • !is_preview()
    This prevents the ads from showing whenever we click Preview on the Post Editor. This is done so that Google Bots won’t crawl the preview page and consequently report the page as missing or status 404.


Add a Comment
  1. You can use multiple Conditional Tags in it with logic operators.

    1. I may have clicked “publish” prematurely. I’ve added your suggestion 🙂

  2. Great post. I’m using the tag wp_is_mobile along with Widget Logic to attempt to customize widgets solely on mobile (ipad, phone, etc.). However, because I’m always calling wp_is_mobile() it’s hard to combine with other logic.

    For example, I’d like to show on all mobile pages except for posts. I’ve tried everything but nothing works. It would seem to me wp_is_mobile(‘page’) || !wp_is_mobile(‘post’) should work – but it doesn’t (perhaps because I need to specify the post names and cannot just block all?

    Any ideas?

    1. According to the codex, wp_is_mobile() does not accept any parameters.

      For example, I’d like to show on all mobile pages except for posts.

      Mobile pages? There is no mobile type of posts/pages. Widget Logic is for Widgets. The conditional wp_is_mobile() will return true if your post/page is being viewed on a mobile device.

      For example, let’s say you have a Text Widget.

      Example 1: wp_is_mobile()
      The conditional above means that your particular Text Widget will only appear to a user who is using a mobile device to browse your posts/pages.

      Example 2: wp_is_mobile() && is_page()
      The conditional above means that your Text Widget will only show if the user is browsing with a mobile device and is viewing a page (not a post).

  3. Hello Ron,

    Firstly thank you for this helpful tutorial. I had absolutely no clue about this conditional stuff…

    I wonder if you could help me. I am building a client website and have setup the sililoqy image slider in the header right widget area. Then my client requested static images in the header area for certain pages. I couldn’t find a solution until someone mentioned widget logic and then I found your page.

    So I used this !is_page ('Wines') to prevent the sililoqy slider from showing up on the Wines page and it worked just fine…

    As soon as I put in two conditional elements !is_page ('Wines') || !is_page ('Cigars') it no longer removes the slider on both pages. I need to actually prevent the slider from showing up on 5 or 6 pages…

    What am I doing wrong?
    Appreciate your help..
    South Africa

    1. Have you tried combining the pages in one conditional tag?
      Ex. !is_page( array('Wines', 'Cigars') )

      1. Hey Ron,
        Yes just tried that and it worked…you are a star!!!

        I will load all the other pages and report back.

  4. Hello, can you tell me right code for this:

    I want widget show All Single blog post except sticky post.

    1. You can use is_single() && !is_sticky()

  5. I have about 30 pages where I need one widget holding an image to change based on the page. There is a different image for each page (e.g. Aerospace, Appliances, Automotive, etc.)

    Is there a way to write an if clause with the page name and the image? Otherwise I foresee having to put 30 text widgets in with one page per widget and the corresponding image.

    1. Widget Logic can’t affect the content of a widget, it only dictates where or when the widget will appear. However, it is possible to achieve what you want using both Widget Logic and PHP Code Widget.

  6. Hi,

    I want that a widget should show across all pages except on two pages. These two pages should have two separate things. Is there a way to restrict things with an exception.

    1. The negation sign (!) mentioned on the post does exactly that.

  7. In my website home page i want to show only widget and no home page/or post will be in home page.i.e. I would like to disable home post from home page, how its possible.

    Thanking in advance

    1. That’s not possible with Widget Logic as it only affects widgets and not the content of a post or page. You’ll have to create your own page template that doesn’t have content.

  8. Thanks for quick reply.

  9. I’m trying to set up widget logic on a woocommerce site. I need specific filters to only show on certain product category pages.

    Do you know how I could do that?


    Does not seem to work for woocommerce product categories.


    1. Woocommerce uses a different category separate from the default WordPress category.
      Try this woocommerce conditional:
      Ex. is_product_category( 'Anime' )

  10. Hi,

    Great post! I broke my head already trying to show a widget on front page, on all categories except one category. I am doing like this:

    is_front_page() || is_category( ) || in_category(‘Category’ )


    what is the difference between iS_category( ) and iN_category( )


    1. is_category() checks if the Category archive page is being displayed.
      in_category checks if the current post belongs to a certain category.

  11. I am using the in_category but it’s making the ad show up on the homepage when the post is the first post on the page. However, I only want my front page ad to show up. Not the in_category ad too. What do I need to do to make the in_category ad not show up on the homepage?

    in_category(“mugshots”) ad is showing up on homepage when a post from the mugshots category is on the homepage (I don’t want this to ad to be on the homepage).

    1. in_category(“mugshots”) && !is_front_page()

  12. Hi Ron,

    Many thanks for a very helpful post.
    I would be grateful if you could help me with the following:
    I wanted to show adsense on all my posts except the pages so I used your tips above and put the following code.

    !is_page( array( 'about-us' , 'privacy-policy' ,  'terms-of-use' ,  'contact' , 'disclaimer') )

    It works fine except for the home page, when I add ‘home’ OR ‘front-page’ it doesn´t work.

    I would be grateful for your response.

  13. Hi Ron,

    Please help me out here.

    How can I put adsense only on the posts and exclude all the pages. I tried a code which you gave above and it works except on the home page. I tried ( home ) ( front-page )


    1. You don’t want to show ads on Pages and the Homepage?
      Try this:

      !is_page() && !is_front_page()
  14. There appears to be conditional widget logic in WordPress without the need for a plugin, but I can’t get it to work with “tags”. I add a Text Widget, but I only want it to display in the sidebar when specific posts are displayed. I create a tag named “literature”. I add that tag to the posts for my book reviews.

    When I click Visibility when creating the Text widget, I select “Show” if “Tag” is “literature”. But when I display one of the book review posts that has that tag, the widget does not appear in the sidebar. If I specify “Show” if “Category” and select a specific Category I have created, this will work if I have selected that specific category. But the book reviews are in a sub-category and I don’t want to have to add conditions for each book review post I have. That is why I want to assign the same “tag” to each book review, and then conditionally display the widget only if the tag matches.
    Any suggestions?

    1. There appears to be conditional widget logic in WordPress without the need for a plugin

      Since you’re using a site and not a self-hosted WordPress then Jetpack plugin is already installed by default. It adds that widget visibility module.

      I am seeing a Literature Text Widget on your sidebar when a post with “literature” tag is shown so you probably sorted this all out.

  15. Still useful for me even after so many years, thank you!

  16. How to write rule to show ads only on monday-friday?

  17. Hi Ron,

    Tks for the tutorial.

    I’m trying to use the logic to display the widget in specific Woocommerce Categories and its subcategories/children categories.

    For now I managed to get it working using the is_product_category and adding all the categories in the array: ( Array ( ‘ Category1’, ‘Category2’, )…

    My question is, since I want the widget to be displayed on that product category and it’s children categories, is there an easy way to do that automatically, without having to add each subcategory to the array?


    1. Hello Bernardo!

      I am also trying to display a widget only in sub-categories that have the display type = Products.

      Did you figure out any solution to this?!

      Thank You.