Here is two very simple tips to let you add your own favicon in your admin area.

In both cases, we will use the admin_head hook.

The first one let you define the favicon for your whole admin area. You have to use it within you theme/child theme functions.php file.

function bweb_admin_favicon() {
    $favicon_url = get_stylesheet_directory_uri() . 'img/icon_bweb.png';
    echo '<link rel="shortcut icon" href="' . $favicon_url . '" />';
}
add_action( 'admin_head', 'bweb_admin_favicon' );

 

The second one let you define your favicon for your own plugin pages only. You have to use this function within your plugin files.

function bweb_plugin_admin_favicon() {
    $screen = get_current_screen();
    if ( $screen->id != 'toplevel_page_' . 'plugin-ID' )
        return;

  	$favicon_url = plugin_dir_url(__FILE__) . 'img/icon_bweb.png';
	echo '<link rel="shortcut icon" href="' . $favicon_url . '" />';
}
add_action( 'admin_head', 'bweb_plugin_admin_favicon' );

 

You have to edit the plugin-ID and replace it by your own plugin ID. If you don’t know it, just go to your plugin page and look at the URL.

/wp-admin/admin.php?page=plugin-ID

 

Post written byBrice CAPOBIANCO

WordPress addict and self-taught. I love to learn and to create, then to share…
Founder of bweb.
Share this post

Your email address will not be published. Required fields are marked *

Show 2 comments

2 comments

  1. Without more information, I’m not able to help. Take care of your favicon’s URL and it should works out of the box.