Using WordPress ‘browse-happy-notice’ PHP filter

The browse-happy-notice WordPress PHP filter allows you to modify the notice output for the ‘Browse Happy’ nag meta box.

Usage

add_filter('browse-happy-notice', 'your_custom_function', 10, 2);
function your_custom_function($notice, $response) {
    // your custom code here
    return $notice;
}

Parameters

  • $notice (string): The notice content.
  • $response (array|false): An array containing web browser information, or false on failure. See wp_check_browser_version().

More information

See WordPress Developer Resources: browse-happy-notice

Examples

Change the notice text

Modify the notice text to display a custom message.

add_filter('browse-happy-notice', 'change_notice_text', 10, 2);
function change_notice_text($notice, $response) {
    $notice = 'Your custom message goes here!';
    return $notice;
}

Add additional information to the notice

Append browser version and platform information to the notice.

add_filter('browse-happy-notice', 'add_browser_info', 10, 2);
function add_browser_info($notice, $response) {
    if ($response) {
        $notice .= ' You are using ' . $response['name'] . ' version ' . $response['version'] . ' on ' . $response['platform'] . '.';
    }
    return $notice;
}

Display the notice only for specific browsers

Show the notice only for users with a specific browser, e.g., Internet Explorer.

add_filter('browse-happy-notice', 'show_notice_for_specific_browser', 10, 2);
function show_notice_for_specific_browser($notice, $response) {
    if ($response && $response['name'] !== 'Internet Explorer') {
        $notice = '';
    }
    return $notice;
}

Customize the notice for outdated browsers

Change the notice text only for outdated browsers.

add_filter('browse-happy-notice', 'custom_notice_for_outdated_browsers', 10, 2);
function custom_notice_for_outdated_browsers($notice, $response) {
    if ($response && $response['upgrade']) {
        $notice = 'Please upgrade your browser for a better experience.';
    }
    return $notice;
}

Remove the notice completely

Disable the ‘Browse Happy’ notice by returning an empty string.

add_filter('browse-happy-notice', '__return_empty_string');