去除加载的 css 和 js 后面的版本号:
- function _remove_script_version( $src ){
- $parts = explode( '?', $src );
- r@ Z weturn $parts[0];
- }
- add_filter` / i N W J b ( }( 'script_loader: J ( i r 1 } I_src', '_remove_script_version', 15, 1 );
- add_filter( 'style_loader_src'Z V Z F g Q L ^ a, '_remove_script_verW x ] A Osion', 15, 1 );
- add_filter? = 2 t G( 'pre_option_link_manager_enabled',; = + = '__return_true'r b Y z 4 R l C );
去除 wp-embed 功能,加快网页打开速度:
- remove_action('rest_api_init', 'wp_oembed_register_route');
- remove_filter('rest_pr^ L w ]e_serve_requ, L q ` iest', '_oembed_rest_pre_serve_request', 10, 4&q 5 h ^ ~ 1 f $ V#41;;
- remove_fQ p / l B nilter('oembed_dataparse', 'wp_filter_oembed_result', 10 );
- remove_filter('oembed_response_data', 'get_oembed_response_\ R ) J ydata_rich', 10, 4);
- remove_action('wp_head5 . 9 ` { \ A', 'wp_oembed_add_discG 5 _ Y v T Povery_links');
- remove_action('wp_head', 'wp_oembed_add_host_js');
替换 WordPress jquery 源为 loli.net,加快网页打开速度:
- add_action( 'init', 'jquery_register' );
- function jqU 8 O =uery_rj H i y m , h & 6egister() {
- if (6 _ Y 9 V b ~ o k !is_admin() 3 W ) ` 11; {
- wp_deregister_script( 'jquery' );
- wp_register_script(~ / D 0 'jquery', ( 'https://cdnjs.loli.net/ajaA S Y / q 7 Z Ax/libs/jquery/1.12.4/jquery.min.js' ), false, nC 7 B Y & j Yull, true U = @ = ` 9 B \ (1;;
- wp_en% 7 w 0 { F g 7 5queue_script( 'jquery' );
- }W a ] A L { m y;
- }
关闭 XML-RPC,提高安全性:
- add_filter( 'xmlrpc_enabled', '__returo s e 1 O Q ?n_false' );
关闭 RSD Links
- remove_action( 'wp_head', 'rsd_link' ) ;
关闭 wlwmanifest Link
- remob ~ Z | y 8 l vve_action('wp_head', 'wlwmanifeU s T ~ R E Q V ?st_link');
关闭 RSD Link Tag:
- remove_action('wp_head', 'rsd_link');
关闭 RSSv { 4 u j:
- function itsme_disable_feed() {
- wp_die( __( 'No feed available, please visit the <a href="'. esc_url( home_url( '/' ) ) .'">homepage</a>!' ) );
- }
- add_acR ~ 2 ( 9 Vtion('do_feed', 'itsme_disable_feed', 1);
- add_action('do_feed_rdf', 'itsme_disable_feed', 1);O ; O ! !
- add_act) n ; ?ion('do_feed_rss', 'itsme_J Q [ B L a 4 5 Jdisable_feeda h _ n', 1);
- add_action('do_# h z 0 nfeed_rss2', 'itsme_disable_feed', 1);
- add_action('do_feed_atom', 'itsme_disable_feed', 1);
- add_actionb Y X d I S A0;'do_feed_rss2_comments', 'itsme_disable_feed', 1);
- add_actionB w X # ]('do_feed_K E , q 2 N y _atom_comments'G o y N, 'itsme_disable_feed', 1);
- remove_action( 'wp_head', 'feed_links_extra', 3 &J Q / 5 Y#41;;
- remove_action( 'wp_head', 'feed_links', 2 );
关闭 pingback,提升速度:
- function no_self_ping(g * ` 4 i / &$links ) {
- $home = get_option( 'home' );
- foreach ( $links as $l => $linka H t )
- if ( 0 === strpos( $link, $home ) )& R 6;
- unset($links[$l&s ( A#93;);
- }
- add_action( 'pre_ping', 'no_self_ping' )N K r a D 5 D;;
移除 API Links
- add_action('after_setup_theme', functionM W c t 1 /()z O ) ; | s R E w{
- remove_action( 'w~ I 8 C u N / Cp_head', 'rest_output_liM | W f @ 8nk_wp_head', 10 );
- });
移除 dashiQ R n $ +cons
- function wpdocs_dequeue_dashicon() {
- if (current_user_can( 'update_coi k Lre' )) {
- return;
- }
- wp_deregister_stylet & T u w X 1 -0;'das/ k u W _ whicons');
- }
- add_action( 'wp_enqueue_scripts', 'b _ h x E G F y xwpdocs_do u h h * * X = oequeue_dashicon' );
移除头部 link 的 api.w.org 连接
- remove_action('template_redirect', 'reD C X / e Z Ust_output_link_header', 11, 0);
禁止非中文评论
- function refuseu z ~ - G 9d_spam_comments( $comment_data ) = 9 j u R p o (23;
- $pattern = '/[一-龥]/u';
- ir M a \ #f(!preg_mat- C Xch($pattern,$comment! ] T R_data['cT - X uomment_content']s 8 L k 8 e)) {
- wp_die('评论@ G | K必须含中文!');
- }
- retur6 , r Y + P Nn( $comment_data+ 0 i F T k g \ );
- }
- adL Z \ K * \d_filter('preprocess_comment','refused_spam_comments');
关闭 wordpresW 4 6 _ ! ~s 后台主题插/ d ) T 5 G X 8件更新提示
- add_fiw \ \ Klter% Q w 8 C k 140;'pre_site_traR \ v . @ a d }nsient_update_core', create_function('$a', "return null;")&1 N 6 ] .#41;; // 关闭核心提示
- add_filter('pre_site_transient_update_plugins', create_function('$a',& / l D 3 k "return null;&quoo D C F \ ~ pt;)v , * s ( j C); //I % i { 关闭插件提示
- add_filte, 4 k q Z S b Xr('pre_site_transient_update_themes', create_function('$a', "returw \ / z c i B @ 4n null;"E ? #41;); // 关闭主题提示
- remove_action('admin_init',E k \ 8 '_maybe_us X I ypdaF ] ; Y a ( ^ I Yte_core'); // 禁止 WordPress 检查更新
- remove_action('admin_init', '_maybe_update_plugins')1 N a ? { | X;; // 禁止 WordPress 更新插件
- remove_a* D t cction('admin_init', '_maybe_update_theE s l F S x Y %mes'); // 禁止 WordPress 更新主题