Using WordPress ‘in_theme_update_message-{$theme_key}’ PHP action

The in_theme_update_message-{$theme_key} WordPress PHP action fires at the end of the update message container in each row of the themes list table.

Usage

add_action('in_theme_update_message-{$theme_key}', 'my_custom_action', 10, 2);

function my_custom_action($theme, $response) {
    // your custom code here
}

Parameters

  • $theme (WP_Theme): The WP_Theme object.
  • $response (array): An array of metadata about the available theme update.
    • new_version (string): New theme version.
    • url (string): Theme URL.
    • package (string): Theme update package URL.

More information

See WordPress Developer Resources: in_theme_update_message-{$theme_key}

Examples

Display a custom update message

Display a custom update message when a new theme version is available.

add_action('in_theme_update_message-mytheme', 'mytheme_custom_update_message', 10, 2);

function mytheme_custom_update_message($theme, $response) {
    echo 'A new version of MyTheme is available! Please update to version ' . $response['new_version'] . '.';
}

Show a warning if the update package is not available

Show a warning message if the theme update package URL is not available.

add_action('in_theme_update_message-mytheme', 'mytheme_warn_no_package', 10, 2);

function mytheme_warn_no_package($theme, $response) {
    if (empty($response['package'])) {
        echo 'Warning: The update package is not available.';
    }
}

Display a link to the theme’s changelog when an update is available.

add_action('in_theme_update_message-mytheme', 'mytheme_changelog_link', 10, 2);

function mytheme_changelog_link($theme, $response) {
    echo 'Check out the <a href="https://mytheme.com/changelog" target="_blank">changelog</a> for more details.';
}

Display a message if the update requires a higher version of WordPress

Show a message if the new theme version requires a higher version of WordPress than the current one.

add_action('in_theme_update_message-mytheme', 'mytheme_wp_version_warning', 10, 2);

function mytheme_wp_version_warning($theme, $response) {
    if (version_compare($GLOBALS['wp_version'], $response['requires'], '<')) {
        echo 'This update requires WordPress version ' . $response['requires'] . ' or higher.';
    }
}

Encourage users to make a backup before updating

Remind users to create a backup of their site before updating the theme.

add_action('in_theme_update_message-mytheme', 'mytheme_backup_reminder', 10, 2);

function mytheme_backup_reminder($theme, $response) {
    echo 'Please make a backup of your site before updating the theme.';
}