Last active
October 13, 2024 07:21
-
-
Save emre-edu-tech/be035cdb34cbd1c48ebd5fc5c3d7ea2e to your computer and use it in GitHub Desktop.
This is a demonstration of how to add different favicons manually in custom wordpress theme using functions.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//It is not super complete but it is ok for the start | |
// Remember that $favicon_path will change according to your assets directory structure | |
function add_favicons() { | |
// declare the path variables | |
$favicon_path = get_template_directory_uri() . '/assets/img/favicon.ico'; | |
$apple_touch_icon_72x72_path = get_template_directory_uri() . '/assets/img/apple-touch-icon-72x72.png'; | |
$apple_touch_icon_114x114_path = get_template_directory_uri() . '/assets/img/apple-touch-icon-114x114.png'; | |
// echo to the wp_head anchor to append to it | |
echo '<link rel="shortcut icon" href="' . $favicon_path . '">'; | |
echo "\n"; | |
echo '<link rel="apple-touch-icon" sizes="72x72" href="' . esc_url($apple_touch_icon_72x72_path) . '">'; | |
echo "\n"; | |
echo '<link rel="apple-touch-icon" sizes="114x114" href="' . esc_url($apple_touch_icon_114x114_path) . '">'; | |
} | |
add_action('wp_head', 'add_favicons'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment