Remove apple-touch-icon link generated by WordPress

I am adding Favicons and Icons to my site manually in a more proper way than what WordPress adds by default. My WordPress is generating the below 4 lines of code automatically.

link rel="icon" href="http://example.com/wp-content/uploads/sites/3/2015/09/cropped-group_logo-32x32.png" sizes="32x32"
link rel="icon" href="http://example.com/wp-content/uploads/sites/3/2015/09/cropped-group_logo-192x192.png" sizes="192x192"
link rel="apple-touch-icon-precomposed" href="http://example.com/wp-content/uploads/sites/3/2015/09/cropped-group_logo-180x180.png"
meta name="msapplication-TileImage" content="http://example.com/wp-content/uploads/sites/3/2015/09/cropped-group_logo-270x270.png"

I tried a lot but could not figure out how to stop WordPress from generating this.

Kindly help

Update: After using the function provided by @Gareth, I am getting the following error:

Warning: array_filter() expects parameter 1 to be array, null given in C:\xampp\htdocs\example\wp-includes\general-template.php on line 2466

Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\example\wp-includes\general-template.php on line 2468

Topic favicon icon Wordpress

Category Web


I was able to use the following in my functions.php to remove the apple-touch-icon:

// Don't use the Site Icon as Apple Touch Icon (instead, use those for favicon & others while the touch icon is provided elsewhere)
function removeAppleTouchIconFilter($string) {
  return strpos($string, 'apple-touch-icon') === false;
}
function prevent_apple_touch_icon_metatag($meta_tags){
    return array_filter($meta_tags, 'removeAppleTouchIconFilter');
}
add_filter('site_icon_meta_tags','prevent_apple_touch_icon_metatag');

This way, it finds the icon within the array of meta tags rather than using a hard-set index value. This should prevent issues if the position of this item in the array ever changes.


Finally I found the answer outside of this place, hence I am posting it here as it may be useful to someone like me.

Simply add this to your functions.php file

remove_action ('wp_head', 'wp_site_icon', 99);

from looking at line 2446 of general-template.php where the meta tags are defined, they are defined in an array of $meta_tags, the only way I could think of to remove the 2 options you want is:

function theme_metatags($meta_tags) {
 array_splice($meta_tags, 2);
}
add_filter('site_icon_meta_tags', 'theme_metatags');

That should remove the last 2 icons from the array which is the 2 lines in your post.

I haven't tested this and it's probably not the ideal solution (hopefully someone else will be able to work out a better way).

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.