代码编织梦想

以下内容都在主题的functions.php文件写入

1.移除WordPress版本信息

remove_action( 'wp_head', 'wp_generator' );
2.移除离线编辑器开放接口

remove_action( 'wp_head', 'rsd_link' );
remove_action( 'wp_head', 'wlwmanifest_link' );
3.移除WordPress头部加载DNS预获取

<link rel='dns-prefetch' href='//s.w.org' />
移除代码

function remove_dns_prefetch( $hints, $relation_type ) {
    if ( 'dns-prefetch' === $relation_type ) {
        return array_diff( wp_dependencies_unique_hosts(), $hints );
    }

    return $hints;
}
add_filter( 'wp_resource_hints', 'remove_dns_prefetch', 10, 2 );
4.移除emoji表情script和style

<script type="text/javascript">
            window._wpemojiSettings = {"baseUrl":"https:\/\/s.w.org\/images\/core\/emoji\/2.3\/72x72\/","ext":".png","svgUrl":"https:\/\/s.w.org\/images\/core\/emoji\/2.3\/svg\/","svgExt":".svg","source":{"concatemoji":"http:\/\/wordpress.cc\/wp-includes\/js\/wp-emoji-release.min.js?ver=4.8"}};
            !function(a,b,c){function d(a){var b,c,d,e,f=String.fromCharCode;if(!k||!k.fillText)return!1;switch(k.clearRect(0,0,j.width,j.height),k.textBaseline="top",k.font="600 32px Arial",a){case"flag":return k.fillText(f(55356,56826,55356,56819),0,0),b=j.toDataURL(),k.clearRect(0,0,j.width,j.height),k.fillText(f(55356,56826,8203,55356,56819),0,0),c=j.toDataURL(),b===c&&(k.clearRect(0,0,j.width,j.height),k.fillText(f(55356,57332,56128,56423,56128,56418,56128,56421,56128,56430,56128,56423,56128,56447),0,0),b=j.toDataURL(),k.clearRect(0,0,j.width,j.height),k.fillText(f(55356,57332,8203,56128,56423,8203,56128,56418,8203,56128,56421,8203,56128,56430,8203,56128,56423,8203,56128,56447),0,0),c=j.toDataURL(),b!==c);case"emoji4":return k.fillText(f(55358,56794,8205,9794,65039),0,0),d=j.toDataURL(),k.clearRect(0,0,j.width,j.height),k.fillText(f(55358,56794,8203,9794,65039),0,0),e=j.toDataURL(),d!==e}return!1}function e(a){var c=b.createElement("script");c.src=a,c.defer=c.type="text/javascript",b.getElementsByTagName("head")[0].appendChild(c)}var f,g,h,i,j=b.createElement("canvas"),k=j.getContext&&j.getContext("2d");for(i=Array("flag","emoji4"),c.supports={everything:!0,everythingExceptFlag:!0},h=0;h<i.length;h++)c.supports[i[h]]=d(i[h]),c.supports.everything=c.supports.everything&&c.supports[i[h]],"flag"!==i[h]&&(c.supports.everythingExceptFlag=c.supports.everythingExceptFlag&&c.supports[i[h]]);c.supports.everythingExceptFlag=c.supports.everythingExceptFlag&&!c.supports.flag,c.DOMReady=!1,c.readyCallback=function(){c.DOMReady=!0},c.supports.everything||(g=function(){c.readyCallback()},b.addEventListener?(b.addEventListener("DOMContentLoaded",g,!1),a.addEventListener("load",g,!1)):(a.attachEvent("onload",g),b.attachEvent("onreadystatechange",function(){"complete"===b.readyState&&c.readyCallback()})),f=c.source||{},f.concatemoji?e(f.concatemoji):f.wpemoji&&f.twemoji&&(e(f.twemoji),e(f.wpemoji)))}(window,document,window._wpemojiSettings);
        </script>
        <style type="text/css">
img.wp-smiley,
img.emoji {
    display: inline !important;
    border: none !important;
    box-shadow: none !important;
    height: 1em !important;
    width: 1em !important;
    margin: 0 .07em !important;
    vertical-align: -0.1em !important;
    background: none !important;
    padding: 0 !important;
}
</style>
移除

remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
remove_action( 'wp_print_styles', 'print_emoji_styles' );
5.移除wp-json链接

<link rel='https://api.w.org/' href='http://wordpress.cc/wp-json/' />
移除

remove_action( 'wp_head', 'rest_output_link_wp_head', 10 );
6.移除 wp-block-library-css 前端 CSS

function fanly_remove_block_library_css() {
    wp_dequeue_style( 'wp-block-library' );
}
add_action( 'wp_enqueue_scripts', 'fanly_remove_block_library_css', 100 );
7.移除前后文、第一篇文章、主页meta信息

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 );
8.移除评论

remove_action( 'wp_head', 'feed_links', 2 );//文章和评论feed
remove_action( 'wp_head', 'feed_links_extra', 3 ); //分类等feed
9.移除wp-json api 功能

[link rel='https://api.w.org/' href='http://example.com/wp-json/' /]
[link rel="alternate" type="application/json+oembed" href="http://example.com/wp-json/oembed/1.0/embed?url=..." /]
[link rel="alternate" type="text/xml+oembed" href="http://example.com/wp-json/oembed/1.0/embed?url=..." /]
移除

remove_action( 'wp_head', 'rest_output_link_wp_head' );
remove_action( 'wp_head', 'wp_oembed_add_discovery_links' );
remove_action( 'template_redirect', 'rest_output_link_header', 11, 0 );
10.隐藏js/css的后缀版本号

function wpdaxue_remove_cssjs_ver( $src ) {
if( strpos( $src, 'ver=' ) )
$src = remove_query_arg( 'ver', $src );
return $src;
}
add_filter( 'style_loader_src', 'wpdaxue_remove_cssjs_ver', 999 );
add_filter( 'script_loader_src', 'wpdaxue_remove_cssjs_ver', 999 );
11.移除短链接shortlink

remove_action('wp_head','wp_shortlink_wp_head',10,0);
移除wp-json

// 屏蔽 REST API
add_filter('rest_enabled', '__return_false');
add_filter('rest_jsonp_enabled', '__return_false');

// 移除头部 wp-json 标签和 HTTP header 中的 link 
remove_action('wp_head', 'rest_output_link_wp_head', 10 );
remove_action('template_redirect', 'rest_output_link_header', 11 );

原文链接:https://kuxl.cn/4388.html

wordpress优化头部-爱代码爱编程

wordpress建站的网页头部有一些不常用的冗余信息,只需要在主题的function.php文件中加入以下代码: remove_action( 'wp_head', 'wp_generator' ); remove_action( 'wp_head', 'rsd_link' ); remove_action( 'wp_head', 'wlwma

wp-爱代码爱编程

在wp-includes\general-template.php function wp_head() {     /**      * Print scripts or data in the head tag on the front end.      *      * @since 1.5.0   

wordpress5.3 在有关wp_head() 和wp_footer()的使用-爱代码爱编程

目录 如何使用wp_head()函数 如何去除多余的样式和脚本 如何添加自己的样式引用呢? 如何使用wp_head()和wp_footer()函数 wp_head()函数常见于html文档的head区域 wp_footer()函数常用于</body>结束前 <!doctype html> <html lang="

php优化加载速度也,优化wordpress的header.php提高加载速度-爱代码爱编程

wordpress网站速度全研究:优化footer.php 去除不必要php函数 1、<?php bloginfo('rss2_url'); ?> 该函数有些主题会出现在footer.php,是WordPress自带的RSS解释地址函数。由于现在的阅读器一般支持直接输入博客地址自动获取RSS地址,以及很多博客也会通过第三方烧录RSS地址

怎么删除feed php,WordPress移除Feed中的WP版本号步骤-爱代码爱编程

使用WordPress的博主普遍都还是非常有安全意识,就是移除WordPress的版本号,以免不良用心的人利用旧版本的漏洞对网站攻击。(免费worpress模板下载) WordPress会在前端代码head中加入以下代码: 使用方法移除后,但是WordPress的Feed中依然还会存在一条:https://wordpress.org/?v=4.

php wphead,WordPress-常用函数wp_head()详细解读及原理-爱代码爱编程

一个重要的函数 原文来源:详情 首先,我们来看一下wp_heade()的相关介绍,引用官方文档进行翻译。 用法:wp_head() 参数:不接受任何参数 返回值:NONE 举例:放在header.php文件内,同时放置与标签前,注意是PHP函数,所以要用; OK,知道了以上这些,让我们一起看下这个函数的原型(源文件在:wp-include

ctfshow php特性 web89-web115 web123-150wp-爱代码爱编程

php特性 参考博客仍然是南神博客 文章目录 php特性web89web90web91web92web93web94web95web96web97web98web99web100web101web102web103web104web105web106web107web108***web109***web110web111web112web113we

普通二本,去了小公司,我也想改变-爱代码爱编程

现在求职市场竞争是比较激烈,而且给人一种好像遍地985,211的感觉。 其实普通学校,二本,三本,还是占绝大多数的。 而且也不是人人都去大厂,很多同学可能也只能去一些小公司。 但如果学历不好,出身不好,才要更努力,不要随波逐流。 知识星球里很多学历很好的录友,都非常努力。 下面这位录友就是普通二本,毕业在小公司,然后也发现要改变自己了,他的经历,

Nginx中的location匹配与rewrite重写跳转-爱代码爱编程

目录 前言 一、rewrite跳转实现 二、rewrite执行顺序 三、rewrite跳转场景 四、语法与flg标记说明 五、Nginx常用的正则表达式符号 ​ 六、location 1.分类  2.常用匹配规则​ 3.优先级  4.示例 5.匹配规则定义 总结: 1.比较rewrite和location 2.rewrite会

用js采集某云音乐的MySQL做一个音乐页面-爱代码爱编程

/点歌api:http://wx0725.top/project/php/jiqiren/xiaodie.php?keyword=点歌+歌名&type=json <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title&g