Clean up and optimize WordPress head tag

If you need to know how to remove RSS Feed URL’s from page head or how to remove post relational…

December 11, 2015

If you need to know how to remove RSS Feed URL’s from page head or how to remove post relational links from wp_head read this article! The way to modify the content in head tag is to use remove_action function and add_filter function to hook the original WordPress functions and modify the html.
You have to add these code, in your functions.php file in your theme, to remove many lines of your head tag that often are not useful for your theme:

function clean_wp_head () {
   remove_action('wp_head', 'wp_generator');
   remove_action('wp_head', 'wlwmanifest_link');
   remove_action('wp_head', 'rsd_link');
   remove_action('wp_head', 'wp_shortlink_wp_head');
   remove_action('wp_head', 'adjacent_posts_rel_link_wp_head', 10);
   remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
   remove_action( 'wp_print_styles', 'print_emoji_styles' );
   add_filter('the_generator', '__return_false');
add_action('after_setup_theme', 'clean_wp_head');

Modify relational links (adjacent_posts_rel_link_wp_head) when SEO Yoast plugin is installed

Sometimes these trick doesn’t remove all the lines. For example, if you have installed the WordPress SEO plugin (YOAST), the above code will not work for the adjacent_posts_rel_link_wp_head and you will still see the rel="next" in the link:

<link rel="next" href="" />

Add these lines to remove the relational post links in your html head if you have Seo by Yoast Plugin installed:

$wpseo_front = WPSEO_Frontend::get_instance();
remove_action('wpseo_head', array( $wpseo_front, 'adjacent_rel_links' ), 21 );


I'm a software engineer, an everyday web developer and a maker. I usually build sites with PHP, within or without WordPress. I build Internet of Things with Arduino and ESP8266. I'm the founder of and and I'm actually the Chief Technical Officer of Better Days web agency.


Add filter on wp_title not working with Yoast SEO plugin

For SEO purposes, in a specific template that has a list of items with pagination, I need to have different…

February 22, 2017

Stop sending email to new user in WordPress admin registration

Prevent WordPress to send notification emails when you manually create new users

March 9, 2017

Generate all old PDF preview images with WordPress 4.7

WordPress 4.7 generates thumbnails for PDF files while uploading them in the media library, this is a really good thing…

December 13, 2016

How to add rel=”nofollow” to links with preg_replace()

Adding rel="nofollow" to external link is a good SEO practice.

September 22, 2015

A new avatar generator for WordPress with get_avatar and Flathash

Brand new avatars for WordPress Gravatar service

April 7, 2017

3 ways to add author’s image in WordPress

Add author's image in WordPress without a plugin

April 5, 2017