Using WordPress ‘maintenance_nag()’ PHP function

The maintenance_nag() WordPress PHP function displays a maintenance nag HTML message to remind users to perform necessary updates.

Usage

To use the maintenance_nag() function, simply add it to your WordPress theme or plugin file where you want the maintenance message to appear.

maintenance_nag();

Parameters

  • None

More information

See WordPress Developer Resources: maintenance_nag

The maintenance_nag() function is part of the WordPress core and is automatically called when required. It is not necessary to manually implement this function in most cases.

Examples

Display Maintenance Nag in the Admin Dashboard

To display the maintenance nag in the admin dashboard, add the following code to your theme’s functions.php file:

add_action('admin_notices', 'display_maintenance_nag');
function display_maintenance_nag() {
    maintenance_nag();
}

Display Maintenance Nag in a Custom Admin Page

To display the maintenance nag in a custom admin page, use the following code:

add_action('admin_menu', 'add_custom_admin_page');
function add_custom_admin_page() {
    add_menu_page('Custom Page', 'Custom Page', 'manage_options', 'custom-page', 'custom_page_callback');
}

function custom_page_callback() {
    maintenance_nag();
    echo '<h1>Custom Admin Page</h1>';
}

Display Maintenance Nag in a Custom Location on the Frontend

To display the maintenance nag on the frontend of your website, use the following code in your theme’s functions.php file:

add_action('wp_footer', 'display_maintenance_nag_frontend');
function display_maintenance_nag_frontend() {
    if (current_user_can('manage_options')) {
        echo '<div class="frontend-maintenance-nag">';
        maintenance_nag();
        echo '</div>';
    }
}

Customize the Maintenance Nag Message

To customize the maintenance nag message, use the following code:

add_filter('update_nag', 'custom_maintenance_nag');
function custom_maintenance_nag($default_message) {
    return '<strong>Custom Message:</strong> ' . $default_message;
}

Disable the Maintenance Nag

To disable the maintenance nag, use the following code:

remove_action('admin_notices', 'update_nag', 3);