当前位置:网站首页>How to replace or disable the default blue favicon ICO Icon

How to replace or disable the default blue favicon ICO Icon

2022-06-10 01:53:00 Shell railing

Recently Wordpress Upgrade the program to 5.6.2 edition , Find front and back office favicon.ico Different icons . The new version will automatically determine , If your WordPress The website is not set favicon.ico Icon , Will display a default Blue logo Icon .

Maybe we are the same as me , I don't like the default favicon.ico Icon , In appearance - Customize , Upload an icon to “ Site identity ” Under the site icon option ; This is because WordPress You will first judge whether you have set this option , If it's set up , The icon you set will be displayed .

Ban WordPress default favicon.ico Icon

We can go through do_faviconico Hook modification WordPress The logic of , To disable the default icon , That is, if the user does not set “ Site icons ”, In the background page , Do not show default WordPress logo Small icons .

Just add the following code to the currently used topic functions.php in , Then empty your browser cache , Force refresh or open a browser that has not visited your site , And you can see the effect .

// Ban  WordPress  default  favicon.ico  Icon 
add_action( 'do_faviconico', function() {
	//Check for icon with no default value
	if ( $icon = get_site_icon_url( 32 ) ) {
		//Show the icon
		wp_redirect( $icon );
	} else {
		//Show nothing
		header( 'Content-Type: image/vnd.microsoft.icon' );
	}
	exit;
} );

WordPress The foreground and background assignments are different favicon.ico Icon

Copy and paste the following code into the topic functions.php file :

//WordPress  The foreground and background assignments are different  favicon.ico  Icon 
if ( !function_exists( 'wp_admin_favicon' ) ) {
  function wp_admin_favicon() {
    echo '<link rel="shortcut icon" href="'.get_bloginfo(%20"template_directory" ).'/images/favicon.ico">';
  }
}
add_action( 'admin_head', 'wp_admin_favicon' );

favicon.ico Put the icon in the theme folder images Under the directory .

原网站

版权声明
本文为[Shell railing]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/160/202206091546444834.html