Created
May 27, 2018 17:27
-
-
Save mtx-z/0f1d066f8c0bc0fd2a724b4044a103d0 to your computer and use it in GitHub Desktop.
WordPress - various removers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Various removers | |
* todo: all may not be still needed/usefull/correct | |
*/ | |
/** | |
* @param $headers | |
* | |
* @return mixed | |
* remove xpingback header | |
*/ | |
function x_pingback_head( $headers ) { | |
unset( $headers['X-Pingback'] ); | |
return $headers; | |
} | |
add_filter( 'wp_headers', __NAMESPACE__ . '\\x_pingback_head' ); | |
/** | |
* remove header info | |
*/ | |
function remove_header_info() { | |
remove_action( 'wp_head', 'feed_links_extra', 3 ); | |
remove_action( 'wp_head', 'rsd_link' ); | |
remove_action( 'wp_head', 'wlwmanifest_link' ); | |
remove_action( 'wp_head', 'wp_generator' ); | |
remove_action( 'wp_head', 'start_post_rel_link' ); | |
remove_action( 'wp_head', 'index_rel_link' ); | |
remove_action( 'wp_head', 'parent_post_rel_link', 10 ); | |
remove_action( 'wp_head', 'adjacent_posts_rel_link_wp_head', 10 ); // for WordPress >= 3.0 | |
} | |
add_action( 'init', __NAMESPACE__ . '\\remove_header_info' ); | |
/** | |
* @return string | |
*/ | |
function head_remove_version() { | |
return ''; | |
} | |
add_filter( 'the_generator', __NAMESPACE__ . '\\head_remove_version' ); | |
add_filter( 'the_generator', '__return_false' ); | |
/** | |
* @param $matches | |
* | |
* @return string | |
* helper for replacing query var of asset from remove_wp_assets_qvar() | |
*/ | |
function removeVersionCallback( $matches ) { | |
return 'ver=' . md5( print_r( $matches, true ) . "" ); | |
} | |
/** | |
* @param $src | |
* | |
* @return mixed|string | |
* Remove assets query var | |
* can be bypassed when forcing nginx pagespeed to process assets from queried URL | |
* By default, pagespeed does not rewrite them | |
*/ | |
function remove_wp_assets_qvar( $src ) { | |
$src = preg_replace_callback( '/ver=[^&]*/', __NAMESPACE__ . '\\removeVersionCallback', $src ); | |
if ( strpos( $src, 'ver=' ) ) { | |
$src = remove_query_arg( 'ver', $src ); | |
} | |
return $src; | |
} | |
add_filter( 'style_loader_src', __NAMESPACE__ . '\\remove_wp_assets_qvar', 9999 ); | |
add_filter( 'script_loader_src', __NAMESPACE__ . '\\remove_wp_assets_qvar', 9999 ); | |
/** | |
* Redirect back helper | |
*/ | |
function redirect_back() { | |
if ( wp_get_referer() ) { | |
wp_safe_redirect( wp_get_referer() ); | |
} else { | |
wp_safe_redirect( get_home_url() ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment