Often times when you are displaying a notification bar or message bar you may want to restrict it to specific posts and pages.
You may want to share a message about a coupon code only on certain product pages.
There are numerous reasons similar to this. Most notification bar plugins do not provide an extensive feature to configure this.
In this article, I’ll use the Announcer WordPress plugin and share how we can use it to display announcements on certain pages.
The Announcer plugin is one of the best plugins to display notification bars with all the features available out of the box. The feature mentioned below is available in the free version itself.
Configuring the Settings
If you are new to the Announcer WordPress plugin, you can learn more about it in the display announcement bar in WordPress getting started guide.
After creating an announcement bar, go to the Announcement edit page.
Under the Settings section, switch to the “Location rules” tab.
You can see 3 options
- Show in all pages
- Hide in all pages
- Show in selected pages
- Hide in selected pages
Show in all pages – Display the announcement bar on all the pages of your website.
Hide in all pages – Hide the announcement bar on all the pages of your website.
Show in selected pages – Display the announcement bar only on specific pages. You can create your own rules.
Hide in selected pages – Hide the announcement bar only on specific pages. You can create your own rules.
What are Rules?
When you select “Show/hide in selected pages” option, you are offered a section where you can build your own rules.
Rules consist of different conditions. A condition consists of 3 elements.
There are different criteria offered by the plugin like Posts, pages, Home page, Front page, Post type, Archive page, etc.
The operator decides how the condition has to be evaluated.
The value is the one where you enter the desired data to be met for the condition.
Let’s say you want to show the announcement only in selected posts. You will add criteria called “Single post” with the operator selected as “is” and value set as the post IDs.
You can also add more sub-conditions to a rule.
If any of the rules are met, then the announcement will be shown/hidden as selected previously.
Creating Custom Rules to Show/Hide Announcement Bar
Now, let’s try to show the announcement only on posts having a specific category.
Select “Show in selected page” and click “Add new rules”
Select “Single post” as criteria, “is” as the operator, and leave the value empty. Here we have added a condition saying that show the announcement in all the “posts”
But we need to show the posts which have a specific category right?
To do this, click the “+” button to add another sub condition to the main one. You will see this condition nested below the main one.
Now select “Categories of post” as criteria, “is” as the operator, and select the category you want as value.
That’s it, now we have added a rule saying show the message bar on all posts, where the category is as selected.
Similarly, you can add more rules for the same notification bar.
Hit publish to save and see the message bar in action only on the posts which has that category.
Similarly, if you want to hide the announcement bar except for the posts which have that category, you can select “Hide in selected pages”.
Displaying notification bars is necessary for any website to gather audience attention and drive sales.
Also, showing them on specific posts and pages makes them special for the audience.
We saw how easy was it to create rules to conditionally display an announcement bar on a WordPress site.
If you have any questions or doubts, please feel free to share them in the comments box below.