探索建站和运维乐趣

禁止WordPress程序ShortLink和REST API以及去掉wp-json教程

我们是否有很多网友发现自己的网站在百度搜索引擎中收录地址有/?p=101这样的地址,也有html静态地址,这个到底是什么问题呢?我们不是在后台固定链接中设置过伪静态。于是我们去查看源代码,发现代码中有ShortLink,然后给出的地址就是动态链接,我们要解决他就要禁止功能。

第一、禁止ShortLink

    // 移除头部shortlink edit by laobuluo.com
    remove_action('wp_head','wp_shortlink_wp_head',10,0); 
    remove_action('template_redirect','wp_shortlink_header',11,0);

这里我们添加到主题设置页面中。

第二、禁止wp-json

这里我们还看到有wp-json,我们也需要禁止掉。

//移除头部 wp-json  edit by laobuluo.com
remove_action('wp_head', 'rest_output_link_wp_head', 10 );
remove_action('template_redirect', 'rest_output_link_header', 11 );

第三、屏蔽 REST API

实际上我们看到代码里还有REST API,实际上我们也是用不到的。

//屏蔽REST API edit by laobuluo.com
add_filter('json_enabled', '__return_false' );
add_filter('json_jsonp_enabled', '__return_false' );
add_filter('rest_enabled', '__return_false');
add_filter('rest_jsonp_enabled', '__return_false');

以后我们老部落会再分享其他关于WordPress优化的方法技巧。

赞(0)
转载保留:老部落 » 禁止WordPress程序ShortLink和REST API以及去掉wp-json教程


关注公众号『老蒋朋友圈』

获取更多建站运营运维新知!
互联网创业、前沿技术......