WordPress.org

Ready to get started?Download WordPress

Plugin Directory

Widget Logic

Widget Logic lets you control on which pages widgets appear using WP's conditional tags. It also adds a 'widget_content' filter.

Why isn't it working?

Try switching to the WP default theme - if the problem goes away, there is something specific to your theme that may be interfering with the WP conditional tags.

The most common sources of problems are:

  • The logic text on one of your widgets is invalid PHP
  • Your theme performs custom queries before calling the dynamic sidebar -- if so, try ticking the wp_reset_query option.

Use 'wp_reset_query' fix option isn't working properly any more

In version 0.50 I made some fundamental changes to how Widget Logic works. The result was that the wp_reset_query was less targeted in the code. If lots of people find this problematic I will look at a general solution, but the main workround is to put wp_reset_query() into your code just before calling a dynamic sidebar.

What's this stuff in my sidebar when there are no widgets?

Since v .50 the widget logic code runs such that when dynamic_sidebar is called in a theme's code it will 'return false' if no widgets are present. In such cases many themes are coded to put in some default sidebar text in place of widgets, which is what you are seeing.

Your options, if you want this default sidebar content gone, are to either edit the theme, or as a work around, add an empty text widget (no title, no content) to the end of the sidebar's widget list.

How do I get widget X on just my 'home' page? (Or on every page except that.)

There is some confusion between the Main Page and the front page. If you want a widget on your 'front page' whether that is a static page or a set of posts, use is_front_page(). If it is a page using is_page(x) does not work. If your 'front page' is a page and not a series of posts, you can still use is_home() to get widgets on that main posts page (as defined in Admin > Settings > Reading).

Logic using is_page() doesn't work

If your theme calls the sidebar after the loop you should find that the wp_reset_query option fixes things. This problem is explained on the is_page codex page.

How do I get a widget to appear both on a category page and on single posts within that category?

Take care with your conditional tags. There is both an in_category and is_category tag. One is used to tell if the 'current' post is IN a category, and the other is used to tell if the page showing IS for that category (same goes for tags etc). What you want is the case when:

(this page IS category X) OR (this is a single post AND this post is IN category X)

which in proper PHP is:

is_category(X) || (is_single() && in_category(X))

How do I get a widget to appear when X, Y and Z?

Have a go at it yourself first. Check out the 'Writing Logic Code' section under Other Notes.

Why is Widget Logic so unfriendly, you have to be a code demon to use it?

This is sort of deliberate. I originally wrote it to be as flexible as possible with the thought of writing a drag'n'drop UI at some point. I never got round to it, because (I'm lazy and) I couldn't make it both look nice and let you fall back to 'pure code' (for the possibilities harder to cater for in a UI).

The plugin Widget Context presents a nice UI and has a neat 'URL matching' function too.

Widgets appear when they shouldn't

It might be that your theme performs custom queries before calling the sidebar. Try the wp_reset_query option.

Alternatively you may have not defined your logic tightly enough. For example when the sidebar is being processed, in_category('cheese') will be true if the last post on an archive page is in the 'cheese' category.

Tighten up your definitions with PHPs 'logical AND' &&, for example:

is_single() && in_category('cheese')

Requires: 2.8 or higher
Compatible up to: 3.8.3
Last Updated: 2014-2-1
Downloads: 762,920

Ratings

4 stars
4.3 out of 5 stars

Support

5 of 24 support threads in the last two months have been resolved.

Got something to say? Need help?

Compatibility

+
=
Not enough data

0 people say it works.
0 people say it's broken.

100,1,1 100,2,2
100,1,1 100,6,6
100,1,1 100,9,9
100,8,8
100,1,1 0,1,0 0,1,0 78,18,14 100,4,4
86,14,12 100,36,36 100,1,1 0,1,0
87,31,27 0,1,0
96,49,47
100,1,1
100,7,7
100,11,11 0,1,0
100,3,3 100,1,1 0,1,0
95,37,35 100,7,7
100,8,8
100,12,12
100,18,18
100,2,2
100,6,6
95,58,55 100,1,1 100,1,1
100,7,7 0,1,0 91,11,10 100,1,1
96,53,51 100,6,6
100,4,4 97,29,28 0,1,0
100,6,6
89,38,34 0,6,0
93,28,26 100,1,1 100,1,1
60,5,3 20,5,1 100,5,5 69,13,9
92,36,33
100,3,3
83,6,5
100,7,7 100,1,1
100,6,6 67,3,2
70,10,7
87,15,13
100,1,1