How to Add a Notification Bar to Your WordPress Website: A Comprehensive Guide
Adding a notification bar to your WordPress website can highlight important messages, promotions, or announcements. In this tutorial, I’ll walk you through creating a custom notification bar that works seamlessly with WordPress.
Since I currently use the KadenceWP theme and Kadence Blocks on WebberZone, some of these instructions reflect their edits.
The screenshot below is what we used for our Black Friday sale. For this tutorial, we’ll create a notification to display on Boxing Day. We will use the Kadence Blocks Countdown block. Alternatively, you can use any other countdown block or countdown creator.

Prerequisites
Basic understanding of PHP and WordPress hooks
- A website running WordPress.
- Access to the theme’s
functions.phpfile or the ability to create a site-specific plugin. - A basic understanding of PHP and WordPress hooks.
Step-by-Step Implementation
1. Creating the Notification Bar Function
Add the following code to your theme’s functions.php file or in a custom plugin:
Let’s break down the above code:
- The
is_page()function in the above example checks if the pages are ID 42 or post_name ‘about-me’ or post_title “Contact”. This is useful for excluding pages where you don’t want the notification to appear. Delete this check if you want to display this across all pages. - We then set an end date for the sale and compared the current time to the end time of the sale. This automatically stops the bar from displaying after the specified date and time and prevents outdated promotions from showing.
- The
$block_contentassignment creates the HTML structure for the notification bar. It includes three main components:- Kadence Blocks‘ Countdown timer: I recommend creating this in the block editor and then copying the code.
- Deal description text: Tell your users what’s in it for them!
- Coupon code and call-to-action button: I’ve linked this to my deals page.
- Finally, we render the blocks using
do_blocks()and output them. add_action( 'wp_body_open', ... )hooks the function to display immediately after the<body>tag opens and ensures that the notification is displayed at the top of the page.
2. Add Styling for the Notification Bar
Include these styles in your theme by hooking into wp_head (as per code below) or with an external stylesheet that is enqueued using wp_enqueue_scriptsOpens in a new window. Alternatively, you can add custom CSS styles using Customiser > Additional CSS. Remember to minify the styles below in your production site.
The above code:
- Creates a function to add custom CSS
- Hooks into
wp_headto inject styles into the page<head> - Uses responsive design principles
- Includes hover effects and mobile responsiveness
3. Optional: Add Body Class for Theme Adjustment
The above code:
- Adds a CSS class to the
<body>tag when the notification is active. - Allows theme-specific adjustments (e.g., padding, layout).
- Provides additional styling flexibility.
4. KadenceWP: Disable Sticky Header
If you had enabled a sticky header, as I had, you would need to disable this. You can find this under Customize > Header > Sticky Header.
Key Considerations when adapting this to your WordPress site.
Customization Options
- Modify the background color
- Change the text and button styles
- Adjust the expiration date
- Add or remove elements as needed
Best Practices
- Keep the notification brief and clear
- Use contrasting colours
- Ensure mobile responsiveness
- Provide a clear call to action
Troubleshooting
- If the bar doesn’t appear, check:
- Correct hook placement
- PHP syntax
- Expiration date
- Conflict with other plugins
Advanced Techniques
- Use transients for performance
- Create an admin option to enable/disable
- Add cookie-based display logic
Compatibility
- Works with most WordPress themes
- Tested with Kadence theme
- Minimal impact on site performance
Conclusion
Adding a notification bar is a powerful way to communicate important information to website visitors. This method provides a flexible, customizable solution that can be easily adapted to various use cases.

