How to clean up unnecessary code in the header section of a WordPress site? illustrations

For a long time, I’ve been using several plug-ins to clean up some fields in WordPress Headers. In most cases, I would say that you don’t usually need a lot of information.

Why did WordPress add these features and links to your site?

well, the reason is obvious. WordPress is a very large CMS platform, used by more than 27% of online blogs. Each publisher has its own requirements. Some like to post articles onwp-adminbrowser pages, some use third-party tools, and some use iOS or Android applications.

if you use the online version to post articles on your WordPress site, you should remove all unnecessary links from your WordPress site. What are the advantages of hiding

?

  1. pages are certainly faster to load
  2. content code than to add
  3. your important website content is now slightly higher than the way search engines read

Let’s take a look at some links in WordPress Headers. The following steps will help you clean up and optimize the header section of your WordPress site.

WordPress to addEditURIto your website Header, which is required if you post articles through third-party tools. How to disable

? Add the following code to your theme functions.php file:

remove_action ('wp_head', 'rsd_link');

2. Deleting the WordPress version number

version number may expose your WordPress version information and give some premeditated people an opportunity. The code below

removes the WordPress version number from the site.

function crunchify_remove_version() {
    return '';
}
add_filter('the_generator', 'crunchify_remove_version');

if you are not writing in Windows Live Writer, you can remove the following content from the WordPress website Header.

adds the following code to your theme function:

remove_action( 'wp_head', 'wlwmanifest_link');

if you use other forms of fixed links, WordPress's default short links are completely meaningless and can be considered removed.

adds the following code to your theme function:

remove_action( 'wp_head', 'wp_shortlink_wp_head');

5. Remove query string from all static resources

How to clean up unnecessary code in the header section of a WordPress site? illustrations1

static resource query string

add the following code, all query strings will be deleted.

function wbolt_cleanup_query_string( $src ){
    $parts = explode( '?', $src );
    return $parts[0];}
add_filter( 'script_loader_src', 'wbolt_cleanup_query_string', 15, 1 );
add_filter( 'style_loader_src', 'wbolt_cleanup_query_string', 15, 1 );

note:explore ('?', $src)will delete everything after the?symbol. If you only want to delete the query string for with ver, replace?with?ver.

WordPress REST API enables CMS to communicate with other Web properties, no matter what programming language they are written in.

however, many websites don't use it, so in most cases, it's just unnecessary code. By default, the title of each site contains a link:

adds the following code to your theme function:

remove_action('wp_head', 'rest_output_link_wp_head', 10);
remove_action('template_redirect', 'rest_output_link_header', 11, 0);

disabling embedding on a WordPress site does the following:

  • it prevents others from embedding your site, and it also prevents you from embedding your site.
  • removes oEmbed-specific JavaScript.
  • disables filtering of oEmbed results.
  • removes the oEmbed discovery link.
  • turns off oEmbed auto-discovery.
  • removes all embedded rewrite rules.
remove_action('wp_head', 'wp_oembed_add_discovery_links', 10);

this is a complete code:

adds the following code to the theme's functions.php file, and everything is ready.

// ******************** Clean up WordPress Header START ********************** //
function wbolt_remove_version() {
    return '';
}
add_filter('the_generator', 'wbolt_remove_version');

remove_action('wp_head', 'rest_output_link_wp_head', 10);
remove_action('wp_head', 'wp_oembed_add_discovery_links', 10);
remove_action('template_redirect', 'rest_output_link_header', 11, 0);

remove_action ('wp_head', 'rsd_link');
remove_action( 'wp_head', 'wlwmanifest_link');
remove_action( 'wp_head', 'wp_shortlink_wp_head');

function wbolt_cleanup_query_string( $src ){
    $parts = explode( '?', $src );
    return $parts[0];
}
add_filter( 'script_loader_src', 'wbolt_cleanup_query_string', 15, 1 );
add_filter( 'style_loader_src', 'wbolt_cleanup_query_string', 15, 1 );
// ******************** Clean up WordPress Header END ********************** //
Disclaimer: All articles on this website, unless otherwise specified or marked, are original and published on this website. Any individual or organization is prohibited from copying, stealing, collecting, or publishing the content of this site to any website, book, or other media platform without the consent of this site. If the content on this website infringes on the legitimate rights and interests of the original author, you can contact us for assistance.