I usually put the icons in an images folder inside my theme so I’d use
1 2 3 4 5 6 | function kia_add_favicon(){ ?> <!-- Custom Favicons --> <link rel="shortcut icon" href="<?php echo get_stylesheet_directory_uri();?>/images/favicon.ico"/> <link rel="apple-touch-icon" href="<?php echo get_stylesheet_directory_uri(); ?>/apple-touch-icon.png"> <?php } add_action('wp_head','kia_add_favicon'); |
edited: to add the apple touch icon per the comment, and to clarify that if you are using a child theme, but the favicon is in the parent theme’s image folder, you’d use
1 | get_template_directory_url(); |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.