Reputation: 4987
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.
Upvotes: 8
Views: 21630
Reputation: 896
If the file /favicon.ico
exists, do nothing and let the server handle the request. For example, www.example.com/favicon.ico
.
Upvotes: 1
Reputation: 215
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
}
Upvotes: 12
Reputation: 84
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:
Upvotes: 6
Reputation: 13257
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
.
Upvotes: 3