怎么移除多余的代碼? – 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| 国产一区二区三区在线看| 国产成人一区二区三区| 日韩一区二区久久久久久| 日本一区高清视频| 久久精品黄AA片一区二区三区| 国产成人高清亚洲一区91| 一区二区三区在线|欧| 四虎一区二区成人免费影院网址| 亚洲国产av一区二区三区丶| 国产成人精品无人区一区| 中文字幕乱码一区久久麻豆樱花| 久久国产高清一区二区三区| 国产精品久久久久久一区二区三区 | 精品一区二区在线观看| 日本免费精品一区二区三区| 3d动漫精品一区视频在线观看| 久久久久女教师免费一区| 午夜视频在线观看一区|