WordPress禁止头部加载oEmbed

今天升级WordPress到4.4,发现文章页面下引用了下面一段代码,我个人认为是没什么用处的,强迫症受不了啊(-?-;),果断去之,百度谷歌都搜索了一下,发现没有好的解决方法。

WordPress禁止头部加载oEmbed

<link rel="alternate" type="application/json oembed" href="https://daliuzi.cn/wp-json/oembed/1.0/embed?url=https://daliuzi.cn/xiu-lite/" />
<link rel="alternate" type="text/xml oembed" href="https://daliuzi.cn/wp-json/oembed/1.0/embed?url=https://daliuzi.cn/xiu-lite/&format=xml" />

然后看了下WordPress的升级日志,发现介绍最下面有移除方法,需要安装插件,下面有插件链接,或者后台插件搜索Disable Embeds安装即可。

官方介绍文档:https://make.wordpress.org/core/2015/10/28/new-embeds-feature-in-wordpress-4-4/

直通车:Disable Embeds

如果像我一样不喜欢用插件可以把下面代码加到functions.php文件内。

//WordPress移除文章头部加载的oEmbed
function disable_embeds_init() {
 global $wp;
 $wp->public_query_vars = array_diff( $wp->public_query_vars, array(
 'embed',
 ) );
 remove_action( 'rest_api_init', 'wp_oembed_register_route' );
 add_filter( 'embed_oembed_discover', '__return_false' );
 remove_filter( 'oembed_dataparse', 'wp_filter_oembed_result', 10 );
 remove_action( 'wp_head', 'wp_oembed_add_discovery_links' );
 remove_action( 'wp_head', 'wp_oembed_add_host_js' );
}
add_action( 'init', 'disable_embeds_init', 9999 );

到这里就算结束了,上面代码取自Disable Embeds插件,

公益传播因为有你,爱不罕见。

转载请注明出处:大刘子 » WordPress禁止头部加载oEmbed

返回首页