Quantcast
Channel: WordPress › Support » Forum: Hacks - Recent Topics
Viewing all articles
Browse latest Browse all 8245

andrejcremoznik on "Conditionally show custom widget in frontend sidebar"

$
0
0

1. I've created a custom widget.
2. This widget is applied to a sidebar area that is active on multiple templates e.g. the archives and singles.
3. I would like to display the widget only if is_single() == true.

There are multiple ways to go about doing that. I could register a new sidebar which would only display on single pages.

What I'd rather do, however, is somehow check the is_single() condition inside the custom widget class. Checking inside the widget() method does hide the content but the is_active_sidebar() still returns true, because it's not aware of the hidden widget's content.

What is the most appropriate way to handle this?

Thanks


Viewing all articles
Browse latest Browse all 8245

Trending Articles