Reputation: 1786
I am trying to change favicon in wordpress. For which i have uploaded image in media and in theme customisation, under site identity i used that image as a favicon.
Which is displaying in my admin panel but not in website browser. I tried to inspect it, so it is showing me below line but not coming image name in href
<link rel="icon" href="" type="image/x-icon">
So for that i need to change my each php file's head with appropriate code that is
<link rel="icon" href="http://my_url/image" sizes="32x32" />
but my question is, is there anyway where i can directly change it without going to all the pages' header in wordpress.
I also tried clearing cache and all the other solution, but not working.
Upvotes: 5
Views: 3296
Reputation: 871
You can make it programatically through functions.php
First, create a function that includes the path to your favicon
function add_favicon() {
$favicon_url = get_stylesheet_directory_uri() . 'your_path';
echo '<link rel="shortcut icon" href="' . $favicon_url . '" />';
}
Now, just make sure that function runs when you're on the login page and admin pages:
add_action('login_head', 'add_favicon');
add_action('admin_head', 'add_favicon');
Upvotes: 5
Reputation: 478
If your wordpress version is 4.2+, just add wp_head()
in your header.php
between <head>
tags:
<?php wp_head(); ?>
You should be able to change the favicon from Administration Screen > Appearance > Customize now.
Function reference: wp_head()
Upvotes: 6