怎么移除多余的代碼? – WordPress教程

    經常發現有很多多余無用的WordPress自帶無效代碼。那么就分享一下本人自用的常用移除多余WordPress代碼集合

    在開發WordPress主題的過程中我們經常發現有很多多余無用的WordPress自帶無效代碼。那么就分享一下本人自用的常用移除多余WordPress代碼集合。

    • 原文參考:www.htm.fun/wordpress-jiao-cheng-chang-yon.html

    在主題根目錄下的functions.php文件中的<?php下添加以下代碼并保存。

    /**********************************************************************
                                去除多余代碼
    **********************************************************************/
    add_filter('show_admin_bar', '__return_false');
    remove_action('wp_head', 'feed_links', 2);
    remove_action('wp_head', 'feed_links_extra', 3);
    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', 'locale_stylesheet');
    remove_action('wp_head', 'noindex', 1);
    remove_action('wp_head', 'wp_print_head_scripts', 9);
    remove_action('wp_head', 'wp_generator');
    remove_action('wp_head', 'rel_canonical');
    remove_action('wp_head', 'wp_shortlink_wp_head', 10, 0);
    remove_action('wp_head', 'wp_oembed_add_host_js');
    remove_action('wp_head', 'wp_resource_hints', 2);
    remove_action('wp_head', 'rest_output_link_wp_head', 10);
    remove_action('wp_head', 'wp_oembed_add_discovery_links', 10);
    remove_action('wp_footer', 'wp_print_footer_scripts');
    remove_action('publish_future_post', 'check_and_publish_future_post', 10, 1);
    remove_action('template_redirect', 'wp_shortlink_header', 11, 0);
    remove_action('template_redirect', 'rest_output_link_header', 11, 0);
    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);
    add_filter( 'pre_option_link_manager_enabled', '__return_true' );
    add_filter('rest_enabled', '__return_false');
    add_filter('rest_jsonp_enabled', '__return_false');
    add_shortcode('reply', 'reply_to_read');
    add_filter('pre_site_transient_update_core',create_function('$a',"return null;")); // 關閉核心提示
    add_filter('pre_site_transient_update_plugins',create_function('$a',"return null;")); // 關閉插件提示
    add_filter('pre_site_transient_update_themes',create_function('$a',"return null;")); // 關閉主題提示
    remove_action('admin_init','_maybe_update_core');// 禁止 WordPress 檢查更新
    remove_action('admin_init','_maybe_update_plugins');// 禁止 WordPress 更新插件
    remove_action('admin_init','_maybe_update_themes'); // 禁止 WordPress 更新主題
    //禁用文章自動保存
    add_action('wp_print_scripts','disable_autosave');
    function disable_autosave(){wp_deregister_script('autosave');
    }
    //禁用文章修訂版本
    add_filter( 'wp_revisions_to_keep', 'specs_wp_revisions_to_keep', 10, 2 );
    function specs_wp_revisions_to_keep( $num, $post ) {return 0;
    }
    // 阻止站內文章互相Pingback
    function theme_noself_ping( &$links ) {$home = get_theme_mod( 'home' );foreach ( $links as $l => $link )if ( 0 === strpos( $link, $home ) )unset($links[$l]);
    }
    add_action('pre_ping','theme_noself_ping');
    

    好啦,這就是本人開發主題的時候自己用的代碼集合咯~如果你覺得不完善,請在下方留言,本人會完善的~

    相關推薦

    怎么移除頭部不必要的元素標簽? – WordPress開發

    hover浮出效果 – CSS筆記

    給TA贊賞
    共{{data.count}}人
    人已贊賞
    ??
    Npcink上的部份代碼及教程來源于互聯網,僅供網友學習交流,若您喜歡本文可附上原文鏈接隨意轉載。
    無意侵害您的權益,請發送郵件至 1355471563#qq.com 或點擊右側 私信:Muze 反饋,我們將盡快處理。
    ?
    購物車
    優惠劵
    搜索
    主站蜘蛛池模板: 国产高清视频一区三区| 大香伊蕉日本一区二区| 免费看AV毛片一区二区三区| 国产主播一区二区三区| 久久国产一区二区三区| 色欲AV无码一区二区三区| 亚洲福利一区二区| 日韩av无码一区二区三区| 好吊视频一区二区三区| 亚洲av成人一区二区三区观看在线| 亚洲一区无码中文字幕| 国产一区二区三精品久久久无广告| 国产在线视频一区二区三区 | 午夜爽爽性刺激一区二区视频| 一区二区视频在线观看| 亚洲无线码在线一区观看 | 亚洲高清成人一区二区三区| 成人区人妻精品一区二区三区| 精品国产乱子伦一区二区三区 | 精品一区二区三区视频| 亚洲国产精品无码第一区二区三区| 精品国产a∨无码一区二区三区 | 久久久精品日本一区二区三区| 国产成人av一区二区三区不卡| 国产一区二区三区福利| 在线一区二区观看| 美女视频免费看一区二区| 精品视频一区二区| 国产一区在线播放| 一区二区中文字幕在线观看| 久久精品国产一区二区三区| 久久精品国产一区二区电影| 日产一区日产2区| 色偷偷久久一区二区三区| 乱码精品一区二区三区| 亚洲av无码成人影院一区| 午夜无码一区二区三区在线观看| 国产av福利一区二区三巨| 亚洲av无码不卡一区二区三区| 亚洲国产福利精品一区二区| 少妇一晚三次一区二区三区|