How to show or hide WordPress widgets on specific pages

It is possible to show or hide WordPress widgets depending on the page, whether the user is logged in and more. Here is a guide.

Widgets, those items in the sidebar or on the home page of WordPress websites, can be controlled and you can choose to display them on some pages, but not others. It is great for customising the views on your website.

Many websites and blogs use a design that includes a sidebar. It can appear on the left or right of the page, but it is most often used on the right. That is because we read left to right and we want the page content to appear first and be read first.

Sidebar widgets can show text, images, links, and more, and they are a great place to put adverts, About Me mini bios, welcome messages, links to articles and so on.

Sometimes you might wish you could display a widget on some pages, but not others. Here are a few examples:

  • You might want to show a certain widget on the home page of your website or blog, but not on posts.
  • You might want to show a widget on posts, but not pages.
  • You might want to show or hide widgets if people are logged in, such as members of your site.
  • You might want to hide all widgets on a landing page for sales, email sign up, courses and other content to avoid distractions.

How do you show or hide widgets depending on the page, status of the user (logged in/out), and so on?

The Jetpack plugin, which is often bundled with a WordPress installation, can do it. If you don’t have it, go to the Plugins section, click the Add New button and search for it. It is free. You can pay for extra features, but the ones we will use here are free.

1 Go to Widgets

Click Appearance in the sidebar in the WordPress admin interface. Click Widgets below and the widgets are shown on the right.

The Appearance, Widgets section of WordPress admin interface

 

2 Expand a widget

I will assume you have a WordPress theme with a sidebar and have one or more widgets in it. Expand a widget by clicking the arrow on the right. A Search widget is shown in my example, but it could be any widget. Click the Visibility button (Jetpack plugin required).

View a widget in WordPress admin interface

 

3 Show or hide the widget

At the bottom of the widget is a Visibility button and clicking it expands a section below that lets you create rules. Select either Show or Hide from the menu. I will Show the widget if certain conditions are met.. This is selected in the rule below. There are many conditions and I will use Page. So the rule is Show if Page is

Show or hide WordPress widgets based on rules

 

4 Select a condition

In the next menu is a very long list of conditions. The screenshot only shows the first few and the list goes on and on. I want to show the Search widget if the page being viewed is the front page – the blog home page.

Set the visibility rules for a WordPress widget

 

5 Save the widget

Here is the final result showing the rule: Show if Page is Front page. All that remains is to click the Save button and it is done.

A rule for displaying a WordPress widget

 

The rule for displaying this widget is clear and simple. This widget will only appear when someone views the home page of the website and it will not appear on any other post or page.

See the blue plus button on the right in that last screenshot? You can add more rules, for example, to hide the widget if the user is logged in. So the widget would then display only if the user was viewing the home page and was not logged in.

You could add a third rule and so on. Just build it up rule by rule to get what you want.

You can show a widgets if a certain category of post is displayed, so if you have a food website, you could have one set of widgets for posts about meat recipes and another set for posts about vegetarian recipes. The possibilities are endless.

 

Affiliate links

Be the first to comment

Leave a Reply

Your email address will not be published.