Conditional tags is a powerful “tool” to control the layout of your WordPress theme. It helps you to control what content is displayed on a particular page that matches the conditions you’ve set.
Previously, we’ve shown you how to create conditional menu based on user roles. However, in today’s tutorial, we’ll show something better, where we’re going to use conditional tags with WordPress menu.
If Menu Plugin
First, we’ll be using a plugin called If Menu. Simply install and activate the plugin, and you’ll see a new drop-down to choose where the item of the menu will be displayed. Tick on the checkbox to enable the feature on your menu item. Then, you’ll see two dropdowns just below it.
As you can see, there are plenty of conditional tags available there. As an example for this tutorial, I’ve set the Sample Page item to be displayed on front page only and therefore it will be hidden on other pages.
Additionally, due to many requests by users, the plugin author has introduced a filter if you’d like to add your own conditional checks to the dropdown. Please see the FAQ page for more information about this.
Menu Item Visibility Control Plugin
Menu Item VIsibility Control plugin is much easier to use, more like Widget Logic plugin but for the menu. Once activated, you’ll see text field.
Simply put any conditional tag in the text field to choose where the item will be displayed.
If you’ve any question regarding this tutorial, please leave your comment below or If you’ve any question related to WordPress, feel free to get in touch with us through our contact page.