8

How can I remove the default favicon link from the WordPress theme? I know I can replace the favicon but I am looking for using the remove_action or something like that which I can place in my functions.php. Thanks.

4 Answers 4

11

I have used the following filter in the theme functions.php file to remove the original WordPress favicon from being output in the wp_head() function.

add_filter( 'get_site_icon_url', '__return_false' );

This filter removes the URL of the chosen image to be a favicon, so it returns false when WordPress checks for the URL to display it.

There is also an option to create a function that displays the favicon on the following actions:

  • wp_head
  • admin_head
  • wp_head

using the following way:

add_action( 'wp_head', 'prefix_favicon', 100 );
add_action( 'admin_head', 'prefix_favicon', 100 );
function prefix_favicon() {
    //code of the favicon logic
    ?>
        <link rel="icon" href="LINK TO FAVICON">
    <?php
}
1
  • 2
    Works great, thank you. The wp_head action is being specified twice though. Commented Dec 3, 2020 at 15:59
6

This question seems quiet old, but new with WordPress 5.4 (03/2020) is a default WP-Favicon, which can be very annoying if you don´t want any. It is also activated for every updated website from version 5.4. Sure, you can change it with the customizer in the normal way, but can´t delete it or need to hack around with transparent images or sth. like that.

Try this little function to remove the favicon (from WP 5.4!) as if it had never been there.

add_action( 'do_faviconico', 'magic_favicon_remover');
function magic_favicon_remover() {
    exit;
}

For more informations, have a look at this:

1
  • This didn't do anything for me. If it did work, a safer bet would be: add_action( 'do_faviconico', '__return_false');
    – Jake
    Commented Apr 4 at 3:16
3

You can just remove this line in header.php:

<link rel="icon" type="image/png" href="http://www.example.com/favicon.png" />

It isn't loaded automatically, so you can't remove it using a filter/remove_action.

1
  • I recommend adding favicon.ico to the root, to avoid load unneeded favicon when files requested.
    – Abouasy
    Commented May 15, 2022 at 5:57
1

If a physical /favicon.ico file exists, do nothing and let the server handle the request. for example www.domain.com/favicon.ico

reference

Not the answer you're looking for? Browse other questions tagged or ask your own question.