<?php
/**
* CubeDesigns - Wordpress Optimizations and Tweaks
*
* Some of the below function are from the Plugin: Meta Generator and Version Info Remover
* (https://wordpress.org/plugins/meta-generator-and-version-info-remover/)
*/
/************************************************************************
* Header items cleaning.
*
* @return void
***********************************************************************/
function cds_clean_the_header_outout() {
remove_action( 'wp_head', 'wp_generator' ); // Remove WP Generator Vesion.
remove_action( 'wp_head', 'wp_resource_hints', 2 ); // Remove s.w.org DNS-Prefetch.
remove_action( 'wp_head', 'wlwmanifest_link' ); // Remove wlwmanifest.xml.
remove_action( 'wp_head', 'rsd_link' ); // Remove Really Simple Discovery Link.
remove_action( 'wp_head', 'wp_shortlink_wp_head', 10, 0 ); // Remove Shortlink URL.
remove_action( 'wp_head', 'print_emoji_detection_script', 7 ); // Remove Emoji's Styles and Scripts.
remove_action( 'wp_print_styles', 'print_emoji_styles' ); // Remove Emoji's Styles and Scripts.
remove_action( 'admin_print_scripts', 'print_emoji_detection_script' ); // Remove Emoji's Styles and Scripts from Admin.
remove_action( 'admin_print_styles', 'print_emoji_styles' ); // Remove Emoji's Styles and Scripts from Admin.
remove_action( 'wp_head', 'index_rel_link' ); // Remove Link to Home Page.
remove_action( 'wp_head', 'feed_links_extra', 3 ); // Remove Every Extra Links to RSS Feeds.
remove_action( 'wp_head', 'adjacent_posts_rel_link_wp_head', 10 ); // Remove Prev-Next Links from Header - Not from Post.
remove_action( 'wp_head', 'adjacent_posts_rel_link', 10, 0 ); // Remove Prev-Next Links.
remove_action( 'wp_head', 'start_post_rel_link', 10, 0 ); // Remove Random Link Post.
remove_action( 'wp_head', 'parent_post_rel_link', 10, 0 ); // Remove parent Post Link.
add_filter( 'the_generator', '__return_false' ); // Remove Generator Name from RSS Feed.
}
add_action( 'after_setup_theme', 'cds_clean_the_header_outout' );
/************************************************************************
* Remove WPML generator
***********************************************************************/
if ( !empty ( $GLOBALS['sitepress'] ) ) {
function cds_remove_wpml_generator() {
remove_action(
current_filter(),
array ( $GLOBALS['sitepress'], 'meta_generator_tag' )
);
}
add_action( 'wp_head', 'cds_remove_wpml_generator', 0 );
}
/************************************************************************
* Remove Slider Revolution generator
***********************************************************************/
function cds_remove_revslider_meta_tag() {
return '';
}
add_filter( 'revslider_meta_generator', 'cds_remove_revslider_meta_tag' );
/************************************************************************
* Remove Visual Composer / WPBakery Page Builder generator
***********************************************************************/
function cds_remove_visual_composer_generator() {
if ( class_exists( 'Vc_Manager' ) || class_exists( 'Vc_Base' ) ) {
remove_action('wp_head', array(visual_composer(), 'addMetaData'));
}
}
add_action('init', 'cds_remove_visual_composer_generator', 100);
/************************************************************************
* Remove comment-reply.min.js completely
***********************************************************************/
function cds_remove_comment_reply_js() {
wp_deregister_script( 'comment-reply' );
}
add_action('init', 'cds_remove_comment_reply_js', 10);
/************************************************************************
* Remove jQuery Migrate Script from header
* and Load jQuery from Google API
***********************************************************************/
function cds_remove_jquery_migrate_load_google_hosted_jquery(){
if (!is_admin()) {
wp_deregister_script('jquery');
wp_register_script('jquery', 'https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js', false, null);
wp_enqueue_script('jquery');
}
}
add_action('init','cds_remove_jquery_migrate_load_google_hosted_jquery');
/************************************************************************
* Remove Yoast SEO comments
***********************************************************************/
function cbs_remove_yoast_seo_comments() {
if ( ! class_exists( 'WPSEO_Frontend' ) ) {
return;
}
$instance = WPSEO_Frontend::get_instance();
// To ensure that future version of the plugin does not cause any problem
if ( ! method_exists( $instance, 'debug_mark') ) {
return;
}
remove_action( 'wpseo_head', array( $instance, 'debug_mark' ), 2 );
}
add_action('template_redirect', 'cbs_remove_yoast_seo_comments', 9999);
add_filter('wpseo_debug_markers', '__return_false', 9999); // Requires Yoast > v14.0
/************************************************************************
* Remove Query Strings (the version) from script and style files,
* some files won't be cached if there is a query string in them
***********************************************************************/
// function cds_remove_script_version( $src ){
// $parts = explode( '?ver', $src );
// return $parts[0];
// }
// add_filter( 'script_loader_src', 'cds_remove_script_version', 15, 1 );
// add_filter( 'style_loader_src', 'cds_remove_script_version', 15, 1 );
/************************************************************************
* remove wp version param from any enqueued scripts
* (using wp_enqueue_script()) or styles (using wp_enqueue_style()).
***********************************************************************/
function cds_remove_appended_version_script_style( $target_url ) {
$filename_arr = explode('?', basename($target_url));
$filename = $filename_arr[0];
/* check if "ver=" argument exists in the url or not */
if (strpos( $target_url, 'ver=' )) {
$target_url = remove_query_arg( 'ver', $target_url );
}
/* check if "version=" argument exists in the url or not */
if (strpos( $target_url, 'version=' )) {
$target_url = remove_query_arg( 'version', $target_url );
}
return $target_url;
}
/**
* Priority set to 20000. Higher numbers correspond with later execution.
* Hook into the style loader and remove the version information.
*/
add_filter('style_loader_src', 'cds_remove_appended_version_script_style', 20000);
/**
* Hook into the script loader and remove the version information.
*/
add_filter('script_loader_src', 'cds_remove_appended_version_script_style', 20000);