-1

I am having troubles with my favicon. I have a WordPress site and I use this code to display the favicon in my functions.php:

function add_my_favicon() {
   $favicon_path = get_stylesheet_directory_uri() . '/favicon.ico';
   echo '<link class="favicon" rel="icon" type="image/x-icon" href="' . $favicon_path . '?" />';
   echo '<link class="favicon" rel="shortcut icon" type="image/x-icon" href="' . $favicon_path . '?" />';
}
add_action( 'wp_head', 'add_my_favicon' ); //front end
add_action( 'admin_head', 'add_my_favicon' ); //admin end

Everything good so far. It works on my homepage site but it does not on all the other sites. For example the favicon is missing on my product detail site. The html source code is loaded correctly everytime but it seems that chrome is somehow overwriting my stylesheet with:

user agent stylesheet:

link {
    display: none;
}

It tried also with Firefox and there it works without problems. Only Chrome is buggy. I disabled also Adblock for my site and still the same issue.

Any more ideas?

Argus Duong
  • 2,356
  • 1
  • 13
  • 24
Nicola
  • 385
  • 1
  • 5
  • 15
  • you can simply add your favicon using Appearance -> Customize. add the Favicon Icon under "Site Icon" and you are done. – WP Learner Jan 08 '18 at 11:07

3 Answers3

0

You can add your favicon under Appearance -> Customize -> Site Identity -> Site Icon

Upload 512 x 512 icon and this icon taking as your site Favicon icon

WP Learner
  • 788
  • 1
  • 13
  • 34
  • Yes I know and I also tried this but I have still the same problem. This is why i tried another way by modifiying functions.php. Forgot to mention this sorry. – Nicola Jan 08 '18 at 11:56
  • @Nicola then there should be error in coding standards. please refer to the wordpress coding standards. why you downvote my answer as it is the best way to do so. ? – WP Learner Jan 09 '18 at 03:44
  • @Nicola You never said you tried this in the original ticket. We are not mind readers so down voting a suggestion like that is poor form. – damienoneill2001 Sep 17 '18 at 08:54
0

You can read more about user agent stylesheets here; What is user agent stylesheet

Have you tried adding some css to your theme? Without a link to your website it's impossible for anyone here to identify exactly which bit of css you would need to change but setting the right class to display: block; or display: inline-block; should do the trick.

Jolo
  • 67
  • 1
  • 1
  • 9
0

Just call the function add_my_favicon at your header.php. It does nothing when you are calling in wp_head & admin_head action. Please find the below code as example :

<html <?php language_attributes(); ?>>
<head>
<meta charset="<?php bloginfo( 'charset' ); ?>">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="profile" href="http://gmpg.org/xfn/11">
<link rel="pingback" href="<?php bloginfo( 'pingback_url' ); ?>">

<?php
    add_my_favicon();
    wp_head();
?>
</head>

Hope it helps.

Tristup
  • 3,603
  • 1
  • 14
  • 26