wordpress
Wordpress

How to change dashboard title in wordpress

You have wanted to change the title of your admin WordPress page but you don’t know how to do that. Even if you don’t know it, you will need in some of your projects where you will have multiple users.

In this post i will be showing you to customize and change the page title of the the dashboard of your admin screen.

 

Change Dashboard name

Change Dashboard name

 

 

Step 1: Changing the title of title tag.

 

This will change the title of the Dashboard. You can name it whatever that will fit the project for example the website name.

 

Title Tag

Title Tag

 

In the functions.php of your theme, you will add these code for the change.

In this case is discrimination to the screen id of admin panel.

add_action( 'admin_title' , 'change_dashboard_title' );

function change_dashboard_title( $admin_title ) {
	
	global $current_screen;
	
	if( $current_screen->id != 'dashboard' ) {
		
		return $admin_title;

	}
	
	$change_title = 'Title 1';

	$admin_title = str_replace( __( 'Dashboard' ) , $change_title , $admin_title );

	return $admin_title;
	
}

 

It will look like this on the screen.

 

Change Title Tag

Changed Title Tag

 

However, the title of page does not change. This hook is only change the title tag.

So, next step will change the page title.

Step 2:  Change the title of page.

 

You will now add the $title in global to change_dashboard_title function.

global $title;

However, $title is variable that is used in the admin panel. If you want to see more detail, please refer to the wp-admin/index.php.

Next, you will now add this code just before the return $admin_title.

$title = $change_title;

 

It looks like this.

 

Change Page Title

Change Page Title

 

 

And the next step is to change the name of the side menu.

Step3 Change the menu name of side menus.

 

You now add this code to functions.php of your theme.

add_action( 'admin_menu' , 'change_dashboard_menu' );

function change_dashboard_menu() {
	
	global $menu;
	
	foreach( $menu as $key => $menu_setting ) {
		
		$menu_slug = $menu_setting[2];

		if( empty( $menu_slug ) ) {
			
			continue;
			
		}
		
		if( $menu_slug != 'index.php' ) {
			
			continue;
			
		}
		
		$menu[ $key ][0] = 'Title 1';

		break;
		
	}
	
}

 

It looks like this.

 

Change Sidemenu name

Change Sidemenu name

 

This ends the tutorial. And the full code we have written so for is.

add_action( 'admin_title' , 'change_dashboard_title' );

function change_dashboard_title( $admin_title ) {
	
	global $current_screen;
	global $title;
	
	if( $current_screen->id != 'dashboard' ) {
		
		return $admin_title;

	}
	
	$change_title = 'Title 1';

	$admin_title = str_replace( __( 'Dashboard' ) , $change_title , $admin_title );
	$title = $change_title;

	return $admin_title;
	
}

add_action( 'admin_menu' , 'change_dashboard_menu' );

function change_dashboard_menu() {
	
	global $menu;
	
	foreach( $menu as $key => $menu_setting ) {
		
		$menu_slug = $menu_setting[2];

		if( empty( $menu_slug ) ) {
			
			continue;
			
		}
		
		if( $menu_slug != 'index.php' ) {
			
			continue;
			
		}
		
		$menu[ $key ][0] = 'Title 1';

		break;
		
	}
	
}

 

If you want to change the other page name / menu name

 

This is a little caution. Because the title is completely different by the page / screen.

Please look at the code of the <h2> tag of the page name.

 

For example to Dashboard,

<h2><?php echo esc_html( $title ); ?></h2>

 

For example to Posts,

<h2><?php
echo esc_html( $post_type_object->labels->name );
if ( current_user_can( $post_type_object->cap->create_posts ) )
	echo ' <a href="' . esc_url( admin_url( $post_new_file ) ) . '" class="add-new-h2">' . esc_html( $post_type_object->labels->add_new ) . '</a>';
if ( ! empty( $_REQUEST['s'] ) )
	printf( ' <span class="subtitle">' . __('Search results for &#8220;%s&#8221;') . '</span>', get_search_query() );
?></h2>

That is the post-type label is called.

So if you want to change the page name, you need to change the post type label.

Following is possible to change the page name at previous code.

  • Dashboard
  • Media Library
  • Widgets
  • Plugins
  • Users
  • Tools
  • Settings

I hope this will help you in getting your work done. If there is any criticism or commendations, please you can drop your views in the comment box.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.