admin_titlefilter-hookWP 3.1.0

Allows you to change the title (<title> meta tag) of an admin page.

Usage

add_filter( 'admin_title', 'wp_kama_admin_title_filter', 10, 2 );

/**
 * Function for `admin_title` filter-hook.
 * 
 * @param string $admin_title The page title, with extra context added.
 * @param string $title       The original page title.
 *
 * @return string
 */
function wp_kama_admin_title_filter( $admin_title, $title ){

	// filter...
	return $admin_title;
}
$admin_title(string)
Page title with additional context appended.
$title(string)
Original page title.

Examples

#1 Data received by the filter

See what data the filter receives on the Dashboard admin page.

add_filter( 'admin_title', 'wp_kama_admin_title_filter', 10, 2 );

function wp_kama_admin_title_filter( $admin_title, $title ){
	print_r( $admin_title ); //> Dashboard ‹ Site Name — WordPress
	print_r( $title); //> Dashboard

	return $admin_title;
}

#2 Add a DEV site marker to the title

When working on a development site, a marker can be added for convenience:

add_filter( 'admin_title', 'wp_kama_admin_title_dev' );

function wp_kama_admin_title_dev( $admin_title ){
	if( wp_get_environment_type() === 'development' ){
		$admin_title = 'DEV ||| ' .  $admin_title;
	}

	return $admin_title;
}

The result might be DEV ||| Dashboard ‹ Site Name — WordPress.

#3 Display the original title

To keep admin page titles concise, display their original title:

add_filter( 'admin_title', 'wp_kama_admin_original_title', 10, 2 );

function wp_kama_admin_original_title( $admin_title, $title ){
	return $title; //> Dashboard
}

#4 Plugin name and version in the admin title

When developing a plugin, it is convenient to see which plugin version is being used. This example displays that information in the admin title:

add_filter( 'admin_title', 'wp_kama_admin_title_based_on_plugin_name', 10, 2 );

function wp_kama_admin_title_based_on_plugin_name( $admin_title, $title ) {
	$plugin = get_plugins()['hello.php'] ?? [];

	if ( $plugin ) {
		$title .= " - {$plugin['Name']} {$plugin['Version']}";
	}

	return $title;
}

The admin home page displays Dashboard - Hello Dolly 1.7.2.

Changelog

Since 3.1.0 Introduced.

Where the hook is called

In file: /wp-admin/admin-header.php
admin_title
wp-admin/admin-header.php 89
$admin_title = apply_filters( 'admin_title', $admin_title, $title );

Where the hook is used in WordPress

Usage not found.