MU-plugin to set 'Site Identity Favicon' across all Multi-sites

Hi.

For quite a few reasons I am having difficulties with ‘stabilizing’ a generic ‘Site Identity Favicon’ across the browsers of my multi-sites (mostly because all sites have individual admins!, who change & delete things at will!)!!!

My assessment is that to set a universal ‘Site Identity Favicon’ via code (in a theme function file or a ‘must use plugin’:wink: would be the way to go!

I note “Method Four” on the resource:-

https://torquemag.io/2017/09/how-to-add-a-favicon-to-your-wordpress-website/

Is a Mu-plugin possible, please?

Could anyone advise me please?

Thanking you in advance.

Regards

John

  • Ash
    • Code Norris

    Hello john

    Yes, you can try mu-plugins option. Just a little change I can recommend. Instead of the following

    add_action('wp_head', 'add_favicon');

    try this:

    add_action('wp_head', 'add_favicon', 999);

    or

    add_action('wp_head', 'add_favicon', 1);

    And then

    function add_favicon() {
    echo '<link rel="shortcut icon" type="image/png" href="'.get_template_directory_uri().'/assets/favicon.png" />';
    }

    Make sure the link to favicon is correct.

    You can use this code in your child theme’s functions.php if the theme is not changed. Otherwise mu-plugin is the best option. To create a mu-plugin, go to wp-content/mu-plugins folder. If there is no mu-plugins folder then, create one. Now, inside the mu-plugins folder create file with name anything.php (make sure file extension is .php). Now start with a <?php tag and then put the above code.

    Have a nice day!

    Cheers,

    Ash