Using WordPress ‘install_themes_pre_{$tab}’ PHP action

The install_themes_pre_{$tab} WordPress PHP action fires before each of the tabs are rendered on the Install Themes page. The dynamic portion of the hook name, $tab, refers to the current theme installation tab.

Usage

add_action('install_themes_pre_{$tab}', 'your_custom_function');
function your_custom_function() {
    // your custom code here
}

Parameters

  • $tab (string): The current theme installation tab. Possible hook names include:
    • install_themes_pre_block-themes
    • install_themes_pre_dashboard
    • install_themes_pre_featured
    • install_themes_pre_new
    • install_themes_pre_search
    • install_themes_pre_updated
    • install_themes_pre_upload

More information

See WordPress Developer Resources: install_themes_pre_{$tab}

Examples

Add a message before the Block Themes tab

Add a custom message before the Block Themes tab is displayed on the Install Themes page.

add_action('install_themes_pre_block-themes', 'add_message_before_block_themes');
function add_message_before_block_themes() {
    echo '<p><strong>Welcome to the Block Themes section!</strong></p>';
}

Inject custom CSS to style the Featured tab on the Install Themes page.

add_action('install_themes_pre_featured', 'add_custom_css_to_featured_tab');
function add_custom_css_to_featured_tab() {
    echo '<style>.featured-theme { border: 2px solid red; }</style>';
}

Display a notification before the New tab

Show a notification message before the New tab on the Install Themes page.

add_action('install_themes_pre_new', 'display_notification_before_new_tab');
function display_notification_before_new_tab() {
    echo '<div class="notice notice-info"><p>Check out the latest themes available!</p></div>';
}

Add custom JavaScript to the Updated tab

Add custom JavaScript to the Updated tab on the Install Themes page.

add_action('install_themes_pre_updated', 'add_custom_js_to_updated_tab');
function add_custom_js_to_updated_tab() {
    echo '<script>console.log("Updated tab loaded!");</script>';
}

Log current tab in the error log

Log the current tab name in the error log file when a tab is rendered on the Install Themes page.

add_action('install_themes_pre_search', 'log_current_tab');
function log_current_tab() {
    error_log('Current tab: Search');
}