"一些代码添加到主� functions.php 文件�化wordpress速度"

Published on Aug. 22, 2023, 12:07 p.m.

/* 将下面的代码添加到 functions.php 文件 禁用全局评论*/

function __disable_feature($data) { return false; }

add_filter(‘comments_number’, ‘__disable_feature’);
      add_filter(‘comments_open’, ‘__disable_feature’);

/* 将下面的代码添加到 functions.php 文件 禁用搜索*/

function fb_filter_query( $query, $error = true ) {

if ( is_search() ) {
$query->is_search = false;
$query->query_vars[s] = false;
$query->query[s] = false;

// to error
if ( $error == true )
$query->is_404 = true;
}
}

add_action( ‘parse_query’, ‘fb_filter_query’ );
add_filter( ‘get_search_form’, create_function( ‘$a’, “return null;” ) );

/* 将下面的代码添加到 functions.php 文件 移除wp_head()函数产生的冗余*/

remove_action( ‘wp_head’, ‘wp_generator’ );
remove_action( ‘wp_head’, ‘rsd_link’ );
remove_action( ‘wp_head’, ‘wlwmanifest_link’ );
remove_action( ‘wp_head’, ‘index_rel_link’ );
remove_action( ‘wp_head’, ‘parent_post_rel_link’, 10, 0 );
remove_action( ‘wp_head’, ‘start_post_rel_link’, 10, 0 );
remove_action( ‘wp_head’, ‘adjacent_posts_rel_link_wp_head’, 10, 0 );
remove_action( ‘wp_head’, ‘rel_canonical’ );
remove_action( ‘wp_head’, ‘feed_links’, 2 );
remove_action( ‘wp_head’, ‘feed_links_extra’, 3 );

Tags: