Favicon.ico file and code to include automatically on theme head

Hello when I generate a code like this on the head.php:

<link rel="icon" type="image/x-icon" href="<?php echo THEME_PATH ?>/assets/icons/favicon.ico" />

It will output like this:

<link rel="icon" type="image/x-icon" href="wp-content/themes/responsive/assets/ico/favicon.ico" />

How do we do it so that it will appear

<link rel="icon" type="image/x-icon" href="/assets/icons/favicon.ico" />

Sorry for this question. I’m a beginner.

I resoved this. My apologies for that short reply. I test to remove the

<?php echo THEME_PATH ?>/ 

and it worked. It should just be

<link rel="icon" type="image/x-icon" href="assets/icons/favicon.ico" />

It’ll be great if the favicon code will be added to the roots theme on future release.

Please don’t post things like this without posting your solution, it’s very frustrating to people who have the same issue that would come across this thread.

I don’t know why you tried THEME_PATH, but the correct way is using get_template_directory_uri()

1 Like

Must be something like this:

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

As I found out, in latest version of sage you should use asset_path function. like this:

<link rel="icon" type="image/x-icon" href="<?= Assets\asset_path('images/favicon.ico') ?>" />

and do not forget to add “<?php use Roots\Sage\Assets; ?>” before using Assets class.

1 Like

Where can I read more about this?

Hi. Where do you guys usually put the favicon stuff? Of course head.php would be a good solution for most occasions, but somehow it doesn’t feel alright. Why not through wp_head();?

What’s the best solution?

It’s built in to WP 4.3 now, I would just use that.


Damn. Didn’t know that. Tried with the suggested 512x512 image and it works flawlessly.

Instructions for how to use the new WP Favicon feature.

It’s under Admin-> Appearance->Customize->Site Identy — Favicon.

They want you to upload a file at least 512pixels.