How to Control Widget Displays with Widget Logic
Hello and welcome to the guide to the Widget Logic WordPress plugin, which is a superb plugin that is used to control the pages on which pages widgets appear on your website, using WordPress conditional tags. It also adds a
widget_content filter, which allows you to modify the text displayed by any widget from your WordPress theme’s
Step 1) On your Dashboard, scroll down to ‘Plugins’ from the left-hand sidebar
Step 2) From the ‘Installed Plugin’ page, click on ‘Add New’ at the top of the page. Alternatively, click on ‘Add New’ from the dropdown menu under ‘Plugins’
Step 3) You will find yourself on the ‘Add Plugins’ page next. From here, use the search box in the top right-hand corner to search for your plugin
Step 4) From the ‘Search Results’ page, find your desired plugin and click the ‘Install Now’ button. Read the details under the blue link marked ‘More Details’ if you are unsure of anything.
Step 5) The plugin will unpack and install on your website. The next step is to hit the blue link marked ‘Activate Plugin’. This will complete the process.
Step 6) You will now be redirected to the ‘Installed Plugins’ page. From here, scroll down and check that your plugin is activated and ready to go.
Step 7) Head to the ‘Widgets’ page, which is found under ‘Appearance’ on the left-hand sidebar of your Dashboard. Scroll down to the bottom of your widget page to find your options for Widget Logic. Start by ticking the boxes for ‘Add ‘Widget_Context’ filter’ (which will allow you to edit the text and appearance of your widgets in your functions.php file, giving you more flexibility with the look of your widgets on each page) and ‘Use ‘wp_reset_query’ fix’ (which is used when you are having issues with the plugin working correctly). Untick these boxes unless you feel like your widgets are going to have trouble working without that added support.
Step 8) The next step is to add Widget Logic to your available widgets. Choose a widget and scroll it across to the sidebar of your choice. A list of options will become available to you (including Name) and you will find Widget Logic at the bottom. Here, you can add conditions for when a widget should appear based on PHP and WordPress conditional tags. Take a read through these if you are not an experienced coder. We have added a list of them for Step 9.
Step 9) Here are some examples of conditional tags using PHP code. They should give you an idea of what to place in the box marked ‘Widget Logic’ at the bottom of each widget.
Step 10) As an example, we have added the
is_home() conditional tag to our Archives widget. This means that the Archives page of the site will now only be available on the Home Page. See Step 11 for the example.
Step 11) When the widget is saved, and you head back to your website, your
is_home() conditional tag should ensure that the Archives widget only shows on the main home page. See the images below for the Home Page (with Archives on the sidebar) and a random post (where Archives does not show because of the Widget Logic conditional tag being used.)