Can I set a browser favicon in .php file?

I have seen similar questions on this site, but all of them were dealing with different languages.

I have a website I am designing in WordPress, and I want to set a favicon for it. If I have the desired icon in a designated location on the site, can I set the favicon with PHP alone, and how would I do it?

Related posts

Leave a Reply

4 comments

  1. echo this in the <head></head> section:

    echo '<link rel="shortcut icon" href="favicon.ico" type="image/x-icon" />';
    

    For WordPress

    Add this line: <link rel="icon" href="http://example.com/favicon.ico" type="image/x-icon"> into header.php from your template

  2. yes you can. just embed you html in that php file:

    echo '<link rel="shortcut icon" href="//cdn.sstatic.net/stackoverflow/img/favicon.ico?v=038622610830">
    ';
    

    Note: this line should be applied into <head></head> elements block to get work it.