×Share this page
 
  

PHP Code for removing all “generator” content from wordpress 4.0 – HTML & Feed/Rss

Dec 7, 2014 under Uncategorized

The code applied for WordPress 4.0, written in PHP to remove such content:

<meta name=”generator” content=”WordPress 4.0″ />
<generator>http://wordpress.org/?v=4.0 </generator>
<link rel=”stylesheet” href=”/style/wp4.css?v=4.0” />
<script type=’text/javascript’ src’/resize.js?ver=4.0‘></script>
<link rel=”EditURI” type=”application/rsd+xml” title=”RSD” href=”/xmlrpc.php?rsd” />
<link rel=”wlwmanifest” type=”application/wlwmanifest+xml” href=”/wlwmanifest.xml” />

functions.php location

Inside your functions.php from your template theme, add the following code:

function whtop_setup()
{
    remove_action( 'wp_head', 'feed_links_extra', 3); // Remove category feeds
    remove_action( 'wp_head', 'feed_links', 2); // Remove Post and Comment Feeds
    remove_action( 'wp_head', 'rsd_link' );
    remove_action( 'wp_head', 'wlwmanifest_link' );
    remove_action( 'wp_head', 'wp_generator' );

    //-- the part connected with FEED generator
    remove_action( 'rss2_head', 'the_generator' );
    remove_action( 'rss_head',  'the_generator' );
    remove_action( 'rdf_header', 'the_generator' );
    remove_action( 'atom_head', 'the_generator' );
    remove_action( 'commentsrss2_head', 'the_generator' );
    remove_action( 'opml_head', 'the_generator' );
    remove_action( 'app_head',  'the_generator' );
    remove_action( 'comments_atom_head', 'the_generator' );
}
add_action( 'after_setup_theme', 'whtop_setup' );

You can debug all these actions looking to $GLOBALS[‘wp_filter’] with var_dump() or look to documented page for actions.

To remove the version from the end of the CSS/Javascript loaded files (part of the HEAD in HTML)


function whtop_remove_src_version( $src ) 
{
    global $wp_version;

    $version_str = '?ver='.$wp_version;
    $version_str_offset = strlen( $src ) - strlen( $version_str );

    if( substr( $src, $version_str_offset ) == $version_str )
    {
        $src = substr( $src, 0, $version_str_offset );
    }

    //-- one more time,  can use & instead of ? at the end!
    $version_str = '&ver='.$wp_version;
    $version_str_offset = strlen( $src ) - strlen( $version_str );
    if( substr( $src, $version_str_offset ) == $version_str )
    {
        $src = substr( $src, 0, $version_str_offset );
    }
    
    return $src;
}

add_filter( 'script_loader_src', 'whtop_remove_src_version' );
add_filter( 'style_loader_src', 'whtop_remove_src_version' );

NOTE: You can change the whtop_setup() or whtop_remove_src_version() function name.

Tried some old recommenced code to remove feed from wp_head but didn’t work for wordpress 4.0. See also other thread to remove comments and feed links in header.

We recommend moving any possible javascript code at the bottom of HTML, instead of using default wordpress system which manages the HEAD section. See Remove Render-Blocking JavaScript

Tags: ,

Comments are closed.