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

    經(jīng)常發(fā)現(xiàn)有很多多余無用的WordPress自帶無效代碼。那么就分享一下本人自用的常用移除多余WordPress代碼集合

    在開發(fā)WordPress主題的過程中我們經(jīng)常發(fā)現(xiàn)有很多多余無用的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;")); // 關(guān)閉核心提示
    add_filter('pre_site_transient_update_plugins',create_function('$a',"return null;")); // 關(guān)閉插件提示
    add_filter('pre_site_transient_update_themes',create_function('$a',"return null;")); // 關(guān)閉主題提示
    remove_action('admin_init','_maybe_update_core');// 禁止 WordPress 檢查更新
    remove_action('admin_init','_maybe_update_plugins');// 禁止 WordPress 更新插件
    remove_action('admin_init','_maybe_update_themes'); // 禁止 WordPress 更新主題
    //禁用文章自動(dòng)保存
    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;
    }
    // 阻止站內(nèi)文章互相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');
    

    好啦,這就是本人開發(fā)主題的時(shí)候自己用的代碼集合咯~如果你覺得不完善,請(qǐng)?jiān)谙路搅粞裕救藭?huì)完善的~

    相關(guān)推薦

    怎么移除頭部不必要的元素標(biāo)簽? – WordPress開發(fā)

    hover浮出效果 – CSS筆記

    給TA贊賞
    共{{data.count}}人
    人已贊賞
    ??
    Npcink上的部份代碼及教程來源于互聯(lián)網(wǎng),僅供網(wǎng)友學(xué)習(xí)交流,若您喜歡本文可附上原文鏈接隨意轉(zhuǎn)載。
    無意侵害您的權(quán)益,請(qǐng)發(fā)送郵件至 1355471563#qq.com 或點(diǎn)擊右側(cè) 私信:Muze 反饋,我們將盡快處理。
    ?
    購物車
    優(yōu)惠劵
    搜索
    主站蜘蛛池模板: 麻豆精品人妻一区二区三区蜜桃| 伊人激情AV一区二区三区| 日韩一区二区三区免费播放| 影音先锋中文无码一区| 免费无码AV一区二区| 少妇人妻偷人精品一区二区| 国产成人久久精品一区二区三区 | 日韩视频在线一区| 中文字幕一区二区在线播放| 无码AV天堂一区二区三区| 97se色综合一区二区二区| 亚洲视频在线一区二区| 国产日韩一区二区三区在线播放| 波多野结衣一区二区三区高清av| 无码精品人妻一区二区三区漫画| 日本精品一区二区三区视频| 无码人妻AⅤ一区二区三区| 亚洲AV无码一区二三区| 一区二区三区电影网| 国精产品一区一区三区有限公司| 国产精品一区二区三区99| 精品无码国产AV一区二区三区| 日韩AV无码久久一区二区| 国产免费一区二区三区免费视频| 精品人妻系列无码一区二区三区| 天码av无码一区二区三区四区| 亚洲视频一区二区三区| 中文字幕无线码一区2020青青| 国产日韩精品一区二区在线观看播放| 日韩少妇无码一区二区三区| 国产精品免费一区二区三区四区| 亚洲AV无码一区二区三区网址| 亚洲一区二区三区在线观看精品中文| 欧亚精品一区三区免费| 亚洲国产一区国产亚洲| 99久久精品国产高清一区二区 | 精品少妇人妻AV一区二区| 亚洲AV网一区二区三区| 亚洲午夜日韩高清一区| 精品动漫一区二区无遮挡| 国产伦精品一区二区三区免费迷|