• harryfear

    (@harryfear)


    Looks like some browsers will on occassion prefer to serve from /favicon.ico if it’s available, rather than respect the WPHEAD rel tags.

    At least in production, we found that to be the case and had to use this snippet to ensure that WordPress’s “new” handling doesn’t cause the WordPress logo itself to be shown instead of our branded favicon from the RealFaviconGenerator plugin.

    function custom_favicon_redirect() {
        // Include the plugin.php file if necessary to use is_plugin_active()
        include_once(ABSPATH . 'wp-admin/includes/plugin.php');
    
        // Check if the specific plugin is active
        if (is_plugin_active('favicon-by-realfavicongenerator/favicon-by-realfavicongenerator.php')) {
            // Check if the request is for the favicon.ico
            if (is_favicon()) {
                // Specify the path to your custom favicon.
                $custom_favicon_url = '/wp-content/uploads/fbrfg/favicon.ico';
    
                // Use an absolute URL if necessary, modifying the home_url() accordingly.
                $absolute_favicon_url = home_url($custom_favicon_url);
    
                // Redirect to the custom favicon.
                wp_redirect($absolute_favicon_url, 301);
                exit;
            }
        }
    }
    
    // Hook the function into 'do_faviconico' action.
    add_action('do_faviconico', 'custom_favicon_redirect');
  • The topic ‘/favicon.ico’ is closed to new replies.