最新消息:

WordPress禁用Embeds, 关闭文章内的链接自动嵌入变成摘要形式, 推荐插件Disable Embeds

经验分享 admin 3009浏览 1评论

WordPress禁用Embeds,WordPress关闭文章内的链接自动嵌入变成摘要形式

WordPress现在的版本插入一个链接,如果对方也是WordPress站点的话,自动会给他变成一个嵌入引用的方式,会显示网址内容的摘要、图片甚至视频。如下图:

 

==============================================

==============================================

==============================================

==============================================

这个功能大部分情况根本就不需要,而且有很坑的几个地方。

如果你发表的文章是这种形式,访客浏览文章出了家在你的这个页面之外,他还会加载引用的那个页面,引用的要是自己网站的还好。如果是别人的,或者国外的。速度就会非常慢。访客也看不到这个网址是啥。

个人建议禁用此功能。

如果不想禁用,偶尔引用下,但是不想某篇文章引用的话。在填入网址时候不要带网址前面的HTTP即可。

下面说下禁用此功能的方法:

1.使用插件Disable Embeds

直接在WordPress后台插件商店里搜索安装即可。

 

2.使用代码的方式禁用。

function disable_embeds_init() {
/* @var WP $wp */
global $wp;
// Remove the embed query var.
$wp->public_query_vars = array_diff( $wp->public_query_vars, array(
'embed',
) );
// Remove the REST API endpoint.
remove_action( 'rest_api_init', 'wp_oembed_register_route' );
// Turn off
add_filter( 'embed_oembed_discover', '__return_false' );
// Don't filter oEmbed results.
remove_filter( 'oembed_dataparse', 'wp_filter_oembed_result', 10 );
// Remove oEmbed discovery links.
remove_action( 'wp_head', 'wp_oembed_add_discovery_links' );
// Remove oEmbed-specific JavaScript from the front-end and back-end.
remove_action( 'wp_head', 'wp_oembed_add_host_js' );
add_filter( 'tiny_mce_plugins', 'disable_embeds_tiny_mce_plugin' );
// Remove all embeds rewrite rules.
add_filter( 'rewrite_rules_array', 'disable_embeds_rewrites' );
}

add_action( 'init', 'disable_embeds_init', 9999 );

/**
* Removes the 'wpembed' TinyMCE plugin.
*
* @since 1.0.0
*
* @param array $plugins List of TinyMCE plugins.
* @return array The modified list.
*/
function disable_embeds_tiny_mce_plugin( $plugins ) {
return array_diff( $plugins, array( 'wpembed' ) );
}

/**
* Remove all rewrite rules related to embeds.
*
* @since 1.2.0
*
* @param array $rules WordPress rewrite rules.
* @return array Rewrite rules without embeds rules.
*/
function disable_embeds_rewrites( $rules ) {
foreach ( $rules as $rule => $rewrite ) {
if ( false !== strpos( $rewrite, 'embed=true' ) ) {
unset( $rules[ $rule ] );
}
}
return $rules;
}

/**
* Remove embeds rewrite rules on plugin activation.
*
* @since 1.2.0
*/
function disable_embeds_remove_rewrite_rules() {
add_filter( 'rewrite_rules_array', 'disable_embeds_rewrites' );
flush_rewrite_rules();
}

register_activation_hook( __FILE__, 'disable_embeds_remove_rewrite_rules' );

/**
* Flush rewrite rules on plugin deactivation.
*
* @since 1.2.0
*/
function disable_embeds_flush_rewrite_rules() {
remove_filter( 'rewrite_rules_array', 'disable_embeds_rewrites' );
flush_rewrite_rules();
}

register_deactivation_hook( __FILE__, 'disable_embeds_flush_rewrite_rules' );

 

将以上代码写入functions.php文件即可禁用。

代码较长,我们可以将上面代码保存为php文件,然后引用这个PHP文件。这样functions.php里面的代码就不会太乱。

这里直接提供下这个php文件的下载。

蓝奏云:https://www.lanzous.com/i51k5ne

如何在functions.php中引用这个PHP?

//禁止加载wp-embeds.mins.js
include (TEMPLATEPATH . '/includes/disable_embeds.php');

 

/includes/disable_embeds.php这个就是你php文件上传的位置,你传到哪里这个位置就改到哪里。别直接复制我这个代码。

 

=========================================

 

当然如果觉得上面的方法太复杂的话,日记哥也测试了懒人的方法,直接装了插件 Disable Embeds 。成功禁用了嵌入。

这个插件搜索不到的话,可以到作者的网站去找 :https://pascalbirchler.com/

wordpress官方下载地址也可以找到:

https://wordpress.org/plugins/disable-embeds/

 

 

转载请注明:日记男孩的博客 » WordPress禁用Embeds, 关闭文章内的链接自动嵌入变成摘要形式, 推荐插件Disable Embeds

赞赏

微信赞赏支付宝赞赏

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

网友最新评论 (1)

  1. 感谢
    辛德林记1个月前 (03-08)回复