最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

wp enqueue script - Stop WordPress editor embedding links

programmeradmin0浏览0评论

There are several posts about this, - but I suspect that it has changed after Gutenberg, since I can't get either of the methods to work.

I'm trying to stop WordPress embedding links, when written in a post. I just want the regular link to display... Nice and blue as always. But it converts it to an Embed URL-object.

Attempt 1) I've tried:

function WPSE_dequeue_scripts(){
    wp_deregister_script('wp-embed');
}
add_action( 'wp_enqueue_scripts', 'WPSE_dequeue_scripts' );

Didn't work. I can still see the wp-embed.min.js being loaded in the network-developer tab:

Attempt 2) I've also tried:

function WPSE_remove_shiftnav_assets(){
    remove_action( 'wp_enqueue_scripts' , 'wp-embed' , 9999 );
}
add_action( 'wp' , 'remove_shiftnav_assets' );

Even though I would strongly prefer something in my functions.php-file to remove this, then I've also tried this plugin here without any result either.

How do I stop it from auto-converting links to that Embed URL?

There are several posts about this, - but I suspect that it has changed after Gutenberg, since I can't get either of the methods to work.

I'm trying to stop WordPress embedding links, when written in a post. I just want the regular link to display... Nice and blue as always. But it converts it to an Embed URL-object.

Attempt 1) I've tried:

function WPSE_dequeue_scripts(){
    wp_deregister_script('wp-embed');
}
add_action( 'wp_enqueue_scripts', 'WPSE_dequeue_scripts' );

Didn't work. I can still see the wp-embed.min.js being loaded in the network-developer tab:

Attempt 2) I've also tried:

function WPSE_remove_shiftnav_assets(){
    remove_action( 'wp_enqueue_scripts' , 'wp-embed' , 9999 );
}
add_action( 'wp' , 'remove_shiftnav_assets' );

Even though I would strongly prefer something in my functions.php-file to remove this, then I've also tried this plugin here without any result either.

How do I stop it from auto-converting links to that Embed URL?

Share Improve this question asked Jun 8, 2019 at 13:57 ZethZeth 9282 gold badges13 silver badges43 bronze badges 5
  • Dequeuing it isn't enough, the order the hooks run in matters, e.g. if you attempt to dequeue it before it's enqueued it won't work ( a bit like closing a door before it's opened, it doesn't do anything, or opening an open box, it doesn't make much sense ). So you did the correct thing, on the correct hook, but you didn't account for "when" you did it – Tom J Nowell Commented Jun 8, 2019 at 14:50
  • Also, did none of the solutions you linked to work? I don't see dequeuing wp-embed in that article, and I'm not sure it will do what you hope it will do either – Tom J Nowell Commented Jun 8, 2019 at 14:52
  • Thanks for weighing in. So how do I figure out which hook to dequeue it on? I tried all kinds of things (several other things, than I mentioned in the question), but without any results. The mentioned attempts are the best attempts, though. – Zeth Commented Jun 8, 2019 at 18:03
  • You're already using the right hook, the problem is not where you do it, it's when, but I'm not sure that it'll do what you want it to do if you manage to dequeue it anyway. Those solutions you linked to assume the classic editor, wp-embed is just a library for displaying embeds, it isn't the part of the block editor that changes URLs into embeds – Tom J Nowell Commented Jun 8, 2019 at 23:55
  • tutorial with code here: kinsta/knowledgebase/disable-embeds-wordpress – majick Commented Jun 9, 2019 at 22:49
Add a comment  | 

1 Answer 1

Reset to default 0

The quickfix: Copy the link into a text-editor and add a space before it. And then copy that new text (with the prefixed space) into whereever you want it.

发布评论

评论列表(0)

  1. 暂无评论