functions.php

optimize seo, security and theme development
with these functions.php code snippets

How To Remove WordPress Version From Header

WordPress is a well-known and widely understood open-source platform for website development with easy customization available at core level. Where this invasion is an advantage it could be a disadvantage as well when we specifically talk about the security aspects. Over time, we have observed that it is easy for bad guys to hack a WordPress website if we don’t make it secure explicitly. In a fresh installation of WordPress, there are many loopholes and we need to apply some optimization rules for WordPress Theme Security.

Why remove WordPress version from header?

The HTML source code of WordPress site tells us that there is a couple of meta tags in the header that aren’t really required. One of them is the version of WordPress software running on your server which can be easily retrieved by looking at your source header. Now this information is a good hint to WordPress hackers who are looking to target blogs and sites that are using the older and less secure versions of WordPress software.

How do I create a PHP function to remove WordPress Version?

You can follow these simple steps to add WordPress Security Function for removing WordPress Version.

Step-1: Go to your theme’s functions.php file at this location
“/wp-content/themes/yourtheme/functions.php”

Step-2: Now create the function and add filter for removing WordPress version from header in ‘functions.php’. If you already haven’t defined any custom functions before, you can add this in the end of file.

This function is returning an empty value that means do not create anything as result.

Step-3: After defining the functionality, it is time to hook this function with the specific filter action “the_generator” that is responsible for adding WordPress version to the header. It would modify the internal data on run-time and remove the information.

add_filter ("tag_name_here", "function_to_add");

First variable being passed to this function defines the specific filter action to which function is hooked and second variable defines the function name that is to be added on hooked event.

Add this one line after closing your function code.