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.

Download Version 0.51

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.

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')

Another source of confusion is the difference between the Main Page and the front page. If you have set your front page to be a static page, use is_front_page() instead of is_page(x).

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

Again, 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))

See also: 'Writing Logic Code' in the Other Notes section.

Requires: 2.8 or higher
Compatible up to: 3.3.1
Last Updated: 2011-12-28 Downloads: 265,842

Average Rating

5 stars
4 stars
3 stars
2 stars
1 star
(408 ratings)

Compatibility

+
=
Works!

21 people say it works.
1 person says it's broken.

Log in to vote.

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
87,31,27
96,49,47
100,1,1
100,7,7
100,11,11
100,3,3 100,1,1
95,37,35 100,7,7
100,8,8
100,12,12
100,18,18
100,2,2
100,6,6
95,57,54 100,1,1
100,7,7 0,1,0 91,11,10
95,22,21