介绍
WordPress 毕竟是外国人开发的系统放到中国来会有一些水土不服,因为有广泛的使用到一些境外网站服务以及一些不必要的功能导致 WP 网站变慢,这里就将介绍如何通过 function.php 来精简 WP。
functions.php 是 WordPress 预留的功能函数文件,专门用于添加各种自定义函数代码。现在的WordPress主题的功能越来越强大了,一般都自带了 functions.php 这个文件(通常在主题根目录)。
WordPress 加速的一个要点就是能不用插件就不要用插件,插件越多网站越慢 。
例如,我的主题目录是:/data/wwwroot/www.cesafe.com/wp-content/themes/cesafe/,那么在该目录下就存在 functions.php 文件,使用代码编辑器修改它。
多余功能,去掉
//屏蔽文章 Embed 功能 remove_action('rest_api_init', 'wp_oembed_register_route'); remove_filter('rest_pre_serve_request', '_oembed_rest_pre_serve_request', 10, 4); remove_filter('oembed_dataparse', 'wp_filter_oembed_result', 10 ); remove_filter('oembed_response_data', 'get_oembed_response_data_rich', 10, 4); remove_action('wp_head', 'wp_oembed_add_discovery_links'); remove_action('wp_head', 'wp_oembed_add_host_js');