How To Control Where Widgets Appear Using WP's Conditional Tags
Let's say you need to control where you display your sidebar widgets and you want a lightweight and flexible solution. This can easily be achieved by leveraging my preferred Wordpress plugin and using Wordpress's conditional tags
1. Install and active the Widget Logic plugin: https://wordpress.org/plugins/widget-logic/
2. Go to appearance > widgets and expand the widget you'd like to control. Find the "widget logic" field at the bottom.
3. You will have to use WP conditional tags to control where the widget is displayed. As an example, let's say you want to show a banner ad on a particular post and no where else. You would add the following code to the sidebar item in the "widget logic" field:
is_single(99) && in_category('category-name')Replace the number '99' with the ID of your post and 'category-name' with the category slug of the post's category. To find the ID of your post, go to Posts in your WordPress admin, and click the post you need the ID of. Then, if you look in the address bar of your browser, you'll see something like this:
http://example.com/wp-admin/post.php?post=1280&action=edit
The number, in this case 1280, is the post ID.
Voila! Your banner ad will now only display on that post! Easy. There are many other ways to use conditional tags with this plugin which are all explained here: https://wordpress.org/plugins/widget-logic/other_n...
Read more about WP conditional tags here: https://codex.wordpress.org/Conditional_Tags
Good luck!
Trev
Join FREE & Launch Your Business!
Exclusive Bonus - Offer Ends at Midnight Today
00
Hours
:
00
Minutes
:
00
Seconds
2,000 AI Credits Worth $10 USD
Build a Logo + Website That Attracts Customers
400 Credits
Discover Hot Niches with AI Market Research
100 Credits
Create SEO Content That Ranks & Converts
800 Credits
Find Affiliate Offers Up to $500/Sale
10 Credits
Access a Community of 2.9M+ Members
Recent Comments
4
Thanks for creating this tutorial. I can't seem to find the place to add the codes in Widget Logic options. http://prntscr.com/8mj6lz
You don't add the code to widget logic options. You go to appearance --> widgets as explained above.
1. http://prntscr.com/8mjkk1
2. http://prntscr.com/8mjjlz
See more comments
Join FREE & Launch Your Business!
Exclusive Bonus - Offer Ends at Midnight Today
00
Hours
:
00
Minutes
:
00
Seconds
2,000 AI Credits Worth $10 USD
Build a Logo + Website That Attracts Customers
400 Credits
Discover Hot Niches with AI Market Research
100 Credits
Create SEO Content That Ranks & Converts
800 Credits
Find Affiliate Offers Up to $500/Sale
10 Credits
Access a Community of 2.9M+ Members
Thanks for the great tip!
You're welcome Mike!