Optimize WordPress Head Tag by Removing Unnecessary “Junk”

Are you a WordPress user who has noticed some code in your tag that doesn’t belong to your theme? This is because WordPress adds actions to your wp_head hook, such as re=”alternative”, rel=”pingpack”, and the current version number of your WordPress installation. While some of these actions may be necessary for your site, others may be considered “junk” and can be removed.

To remove these actions, you will need to use the remove_action function. This function removes the function from the hook before it runs, preventing it from running altogether. However, it is important to ensure that the priority used for the remove_action function matches the priority used for the add_action function.

For example, if you want to remove the rsd link, you would use the following code:

remove_action( ‘wp_head’, ‘rsd_link’ );

Similarly, if you want to remove the WordPress generator tag, you would use:

remove_action( ‘wp_head’, ‘wp_generator’ );

Other actions that can be removed include RSS feed links, the link to the Windows Live Writer manifest file, adjacent post links, and emoji detection scripts.

To implement these changes, simply paste the code into your child theme’s functions.php file. However, it is not recommended to add this code to a theme for sale or distribution, as it takes away from the end user’s control over their site.

Alternatively, you can use a plugin such as “CC Clean Head Tags” to remove unnecessary code from your WordPress site’s head tag. This free plugin can be activated on your site to streamline your header and improve your site’s performance.

In conclusion, while some actions added by WordPress may be necessary for your site, others can be considered “junk” and removed using the remove_action function or a plugin. By streamlining your header, you can improve your site’s performance and provide a better user experience for your visitors.

Stay in Touch

spot_img

Related Articles