How to Add Browser Tab Notifications in WordPress
In this article
Browser tab notifications (also called favicon badges or title alerts) show a small number or message on the browser tab when something happens on your site—like a new comment, a form submission, or a WooCommerce order. This guide shows you how to add them using a plugin or custom code, so you never miss important activity while working in other tabs.
What You'll Need
- A WordPress site (self-hosted, not WordPress.com free plan) with admin access.
- FTP or cPanel access if you choose the custom code method (optional but recommended).
- A code editor (like Notepad++ or VS Code) for editing functions.php or a custom plugin.
Step-by-Step
Method 1: Using a Plugin (Easiest)
- Log in to your WordPress admin dashboard.
- Go to Plugins → Add New.
- Search for "browser tab notification" or "favicon alert". Popular options include Favicon Alert or WP Notification Center (check compatibility with your WordPress version).
- Click Install Now on the plugin you choose, then click Activate.
- After activation, find the plugin's settings page (usually under Settings or a new menu item like Notifications).
- Configure the trigger: select which events should show the notification (e.g., new comment, new order, form submission). Most plugins let you choose multiple triggers.
- Set the display style: choose whether to show a number badge, a text title change, or both. Some plugins allow custom colors and animation.
- Save your settings. Test by opening your site in another browser tab and triggering the event (e.g., submit a test comment). The tab should update.
Method 2: Adding Custom Code (No Plugin)
- Create a backup of your WordPress site (especially the theme files) before editing.
- Access your theme's
functions.phpfile. You can do this via Appearance → Theme File Editor in the admin, or via FTP/cPanel. - Add the following JavaScript code to your theme's footer (or use a plugin like Insert Headers and Footers). This code changes the document title when a new notification is triggered. For a simple example, add this to your theme's
footer.phpjust before</body>:
<script>
// Example: Change tab title when a new comment is pending
jQuery(document).ready(function($) {
// Check if there are pending comments (example via AJAX)
$.post(ajaxurl, { action: 'check_pending' }, function(response) {
if (response > 0) {
document.title = '(' + response + ') ' + document.title;
}
});
});
</script>
- To make this work, you need to create an AJAX handler in
functions.phpthat returns the number of pending notifications. Add this PHP code:
add_action('wp_ajax_check_pending', 'my_check_pending_notifications');
add_action('wp_ajax_nopriv_check_pending', 'my_check_pending_notifications');
function my_check_pending_notifications() {
// Example: count pending comments
$comments = get_comments(array('status' => 'hold', 'count' => true));
echo intval($comments);
wp_die();
}
- Save the files. Test by opening your site in a new tab and adding a comment that goes to moderation—the tab title should show the count.
Note: For real-time updates (like new orders), you'll need to use WebSockets or periodic AJAX polling. The above example checks once on page load; for continuous updates, set an interval (e.g., every 30 seconds) to re-fetch.
Common Mistakes
- Not enqueuing scripts properly: Adding JavaScript directly in footer.php without using
wp_enqueue_scriptcan cause conflicts with other scripts. Use proper hooks. - Forgetting to use
wp_die()in AJAX handlers: This is required to end the AJAX request correctly. - Hardcoding AJAX URL: Use
admin_url('admin-ajax.php')and pass it to JavaScript viawp_localize_script. - Not testing on multiple browsers: Some older browsers may not support certain features. Test on Chrome, Firefox, and Safari.
- Overwriting the original title: If you don't store the original title, you'll keep adding prefixes. Save it once and restore when count is zero.
Tips
- Use a plugin like Favicon Alert that handles all the complex code for you—it's more reliable and easier to update.
- For WooCommerce stores, consider a dedicated plugin like WooCommerce Notification that integrates with orders.
- Combine tab notifications with a sound alert (using the Web Audio API) for critical events, but ensure it's not annoying.
- Use
document.titlechanges for text alerts and a canvas-based favicon for number badges. Many plugins do both. - Cache the notification count to reduce server load, especially on high-traffic sites.
Troubleshooting
- Notification doesn't appear: Check browser console (F12) for JavaScript errors. Ensure your AJAX URL is correct and that you've enqueued scripts properly.
- Count is always zero: Verify that the AJAX handler is being called. Add a
console.log(response)to debug. Also check that the status you're counting is correct (e.g., 'hold' for pending comments). - Title changes but then reverts: Your code might be running on every page load and resetting the title. Store the original title in a variable and only prepend when count > 0.
- Plugin conflicts: Deactivate other plugins one by one to see if any conflict. Check the browser console for errors like "jQuery is not defined".
- Favicon badge not showing: Some browsers (Safari) don't support canvas-based favicons. Use a fallback like changing the title only.
- AJAX requests slow down site: Increase the polling interval (e.g., from 10 seconds to 60 seconds) or use server-sent events for real-time.
Frequently Asked Questions
Do browser tab notifications work on mobile devices?
No, they only work on desktop browsers. Mobile browsers don't display tab titles or favicons in the same way.
Can I show a notification for new comments only, not all activity?
Yes, most plugins let you select specific triggers. In custom code, you can filter by the event type (e.g., only count comments with status 'hold').
Will this slow down my website?
If you use AJAX polling frequently, it can increase server load. Use reasonable intervals (30-60 seconds) and cache counts to minimize impact.
Can I use this to notify admins only?
Yes, you can restrict the notification to logged-in users with admin capabilities by checking current_user_can('manage_options') in the AJAX handler.
Is there a way to make the notification disappear when I click the tab?
Yes, you can add a click event that clears the title or badge. Many plugins have this feature built in.
Do I need to know PHP to use custom code?
Basic PHP is helpful, but you can copy-paste the provided code. If you're not comfortable, stick with a plugin.