How to add favicon in wordpress website?

Make sure you used this before </head>

If you have favicon as .ico format, you can use this code.

<link type="image/x-icon" rel="shortcut icon" href="<?php echo get_template_directory_uri(); ?>/img/favicon.ico">

If you have favicon as png image format, you can use this code. Make sure your favicon size is 16x16px

<link rel="shortcut icon" type="image/png" href="<?php echo get_template_directory_uri(); ?>/img/favicon.png"/>

You can register favicon via functions.php too. See this code

function my_theme_add_favicon(){ ?>
    <!-- Custom Favicons -->
    <link rel="shortcut icon" href="<?php echo get_stylesheet_directory_uri();?>/img/favicon.ico"/>
    <?php }
add_action('wp_head','my_theme_add_favicon');
The following two tabs change content below.

Leave a Reply

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