Search code examples
wordpresscustomizationfavicon

changing favicon in wordpress theme


I am customizing a a word press theme for my blog. I am trying to change the favicon, But I do not know how to do that. I checked all settings, there is no option for favicon. Can anybody will tell me how to change that.


Solution

  • I usually add a favicon in my site's root directory because some browsers look there by default.

    function so18074365_favicon() {
      printf( "<link rel=\"shortcut icon\" type=\"image/vnd.microsoft.icon\" href=\"%s/favicon.ico\" />\n", site_url() );
    }
    
    add_action( 'wp_head', 's018074365_favicon' );
    

    Add this function to your functions.php and upload your favicon.ico to your wordpress root folder.

    If you want to add the favicon in yout theme folder, add this one:

    function so18074365_favicon() {
      printf( "<link rel=\"shortcut icon\" type=\"image/vnd.microsoft.icon\" href=\"%s/favicon.ico\" />\n", get_stylesheet_directory_uri() );
    }
    
    add_action( 'wp_head', 's018074365_favicon' );