WordPress真的是太臃肿了,各种用不到的功能,还容易被黑客一天到晚暴力破解。
每次换主题也不至于总是去改主题的functions.php文件,直接弄个插件,把要去掉的功能放插件里面。复制下面的代码,新建一个名字为remove-functions.php的文件(记得是UTF-8)格式,放进WordPress目录下/wp-content/plugins/即可,然后去后台插件启用。
<?php
/*
Plugin Name: 小插件
Plugin URI: https://blog.69cdn.com/disable-wordpress-unnecessary-functions/
Description: 禁用一些毫无用处的功能
Version: 0.1
Author: alect
*/
// Add custom Theme Functions here
// disable XML-RPC
add_filter( 'xmlrpc_enabled', '__return_false' );
// remove RSD Links
remove_action( 'wp_head', 'rsd_link' ) ;
// remove wlwmanifest Link
remove_action('wp_head', 'wlwmanifest_link');
// remove version from head
remove_action('wp_head', 'wp_generator');
// remove version from rss
add_filter('the_generator', '__return_empty_string');
// remove version from head
remove_action('wp_head', 'wp_generator');
// remove version from rss
add_filter('the_generator', '__return_empty_string');
// remove version from scripts and styles
function shapeSpace_remove_version_scripts_styles($src) {
if (strpos($src, 'ver=')) {
$src = remove_query_arg('ver', $src);
}
return $src;
}
add_filter('style_loader_src', 'shapeSpace_remove_version_scripts_styles', 9999);
add_filter('script_loader_src', 'shapeSpace_remove_version_scripts_styles', 9999);
// Remove the Shortlink Tag
add_filter('after_setup_theme', 'remove_redundant_shortlink');
function remove_redundant_shortlink() {
// remove HTML meta tag
// <link rel='shortlink' href='http://example.com/?p=25' />
remove_action('wp_head', 'wp_shortlink_wp_head', 10);
// remove HTTP header
// Link: <https://example.com/?p=25>; rel=shortlink
remove_action( 'template_redirect', 'wp_shortlink_header', 11);
}
// Disable Self Pingbacks
function no_self_ping( &$links ) {
$home = get_option( 'home' );
foreach ( $links as $l => $link )
if ( 0 === strpos( $link, $home ) )
unset($links[$l]);
}
add_action( 'pre_ping', 'no_self_ping' );
// Remove REST API Links
add_action('after_setup_theme', function(){
remove_action( 'wp_head', 'rest_output_link_wp_head', 10 );
});
// Add CORS Header
function add_cors_http_header() {
header("Access-Control-Allow-Origin: *");
}
add_action('init','add_cors_http_header');
?>
“禁用WordPress一些毫无用处的功能”上的3条回复
问题是都禁用了啥,也不列出来 emmm
哈,倒是没想到真有人来看啊。
去掉一些头部无用的数据,具体禁用了哪些函数// disable后面都写了,可以搜索下。
实在是太懒,不写说明书了。
忘记哪里过来的了,好像是个啥东西链接博客的
这些东西看了下 好像一直是改文件的 emmmm