67

Question

  1. What does the wp-embed.min.js file do? I noticed it is added to the end of my blog page footer.
  2. How can I get rid of it?

Effort

After some googling and I found Embeds on the Codex. Why does WordPress think I want to add videos, etc. to my page by default?

Environment

WordPress 4.4

4
  • 1
    This is probabli related to wp as oEmbed server and not a client Commented Dec 14, 2015 at 5:25
  • I tried to add the answer to the first part of the question
    – prosti
    Commented Nov 28, 2016 at 19:06
  • 15
    Pretty sure it's just there to slow down your page.
    – vhs
    Commented Apr 17, 2017 at 19:36
  • @MarkKaplun is correct. wp-embed.min.js allows you to embed posts from remote WordPress sites into your own WordPress site, via oEmbed. Commented Nov 15, 2017 at 2:47

5 Answers 5

82

What is it?

It is responsible for converting links into embed frames.

For example you can paste a Youtube video link into the editor content section and the Youtube embed will be generated for you when your page is viewed.

More information on WordPress Documentation

How to get rid of it?

I could finally get rid of that using this:

function my_deregister_scripts(){
  wp_deregister_script( 'wp-embed' );
}
add_action( 'wp_footer', 'my_deregister_scripts' );
7
  • 4
    Adding it on action "wp_enqueue_scripts", also seems to work. Commented Jan 13, 2016 at 16:09
  • 8
    Yes, I'd use the wp_enqueue_scripts hook and wp_dequeue_script() instead of wp_deregister_script()
    – swissspidy
    Commented Jan 17, 2016 at 20:06
  • @swissspidy wp_dequeue_script( 'wp-embed' ); will not work - can you please run a test? The hood recommendation is valid.
    – Aziz
    Commented May 5, 2016 at 22:38
  • Under WordPress 4.6 @Trix script works fine. Thank you!
    – Sebastian
    Commented Sep 6, 2016 at 9:07
  • 1
    Using this wont pass themecheck.
    – lowtechsun
    Commented Jun 12, 2017 at 10:28
35

I arrived at this thread with the same question: What does the wp-embed.min.js file do? None of the current answers accurately address this question.

Firstly, I am fairly certain that embed.min.js does not relate to embedding oEmbed content from other providers: Vimeo, YouTube etc. You can remove embed.min.js and those embeds will continue to function.

It relates specifically to embeding WordPress posts from other people's blogs/websites. Embedding WordPress posts inside WordPress posts: so meta! This feature was introduced in WordPress 4.4.

Disabling embed.min.js will stop that feature from working on your site.

You can test this easily: Paste the URL of someone else's WordPress post into one of your own posts. WP should convert that URL into an embedded widget. When you view your post on the front-end you will notice that your markup contains a blockquote and an iframe. The blockquote is a text-only link to the blog post you embedded, while the source of the iFrame is the blog post's URL with /embed/ appended: its oEmbed endpoint.

embed.min.js hides the blockquote and reveals the iframe. It also does some other shenanigans to make the iframe play nice.

Now, try removing the embed.min.js script from your page using one of the methods described in the other answers. Reload your page and you'll notice that the blockquote is visible but the iframe is hidden.

In short: if you want to embed other people's WordPress posts into your own WordPress posts, leave embed.min.js alone. If you don't care about this feature then you can safely remove it.

4
  • 4
    Note that removing embed.js is not enough to properly disable embeds and might even lead to weird behavior if not done right. To completely disable these embeds, use the officially recommended Disable Embeds plugin.
    – swissspidy
    Commented Jan 22, 2018 at 14:09
  • Working as expected and explained in word-press 5.x as well.
    – inrsaurabh
    Commented Mar 9, 2019 at 12:30
  • 2
    Incredible how wp adds useless bloat with every single version and official theme. Commented Jul 20, 2020 at 20:49
  • 1
    @swissspidywho recommends it? Seems abandoned. Commented Jul 20, 2020 at 20:50
9

Trix's answer didn't work out for me on WordPress 4.4.1, but I found a solution in the code of Disable Embeds WordPress plugin. Add this code (modified) in your theme's functions.php file to remove the wp-embed.min.js file from the frontend completely:

add_action( 'init', function() {

    // Remove the REST API endpoint.
    remove_action('rest_api_init', 'wp_oembed_register_route');

    // Turn off oEmbed auto discovery.
    // 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');
}, PHP_INT_MAX - 1 );
4
  • 3
    Using disable_embeds_init() as the function name is a really bad idea. If you're going to install the Disable Embeds plugin one day, sky will fall down. I recommend you to just install the plugin, there's no benefit in adding this to your theme's functions.php file. If you insist on doing so, you should really use another function name.
    – swissspidy
    Commented Jan 17, 2016 at 20:08
  • Thanks for the suggestion @swissspidy, I have updated the function's name Commented Jan 18, 2016 at 11:59
  • 2
    Note that this won't just remove the JS from the frontend/backend, it will also completely disable the ability to embed your posts on another site, WP Oembed will not work
    – Tom J Nowell
    Commented Nov 4, 2016 at 19:37
  • 1
    Article on Kinsta elaborates on this method of using filters to remove it kinsta.com/knowledgebase/disable-embeds-wordpress Commented Aug 30, 2019 at 13:47
4

I think this part is still missing.

What does the wp-embed.min.js file do? I noticed it is added to the end of my blog page footer.

The answer to this question is in the track. https://core.trac.wordpress.org/changeset/35708

Embeds: Remove & characters from the inline embed JS.

Older versions of WordPress will convert those & characters to &, which makes for some non-functional JS. If folks are running an older release, let's not make their lives more difficult than it already is.

It will also try to sniff the user agent.

1
  • 4
    The text you have quoted ("Remove & characters from the inline embed JS" etc.). is a single commit message for the file, but does not describe the overall purpose of the script. I have provided my own answer which hopefully sheds more light. Commented Nov 15, 2017 at 2:23
1

Aug 2022 - WordPress 6.0.1

Others have given answers to OP's doubt.
I am just giving more insight into wp-embed

What does the wp-embed.min.js file do?

In short, It will make your link pretty

Add a block that displays content pulled from other sites, like Twitter or YouTube.
WordPress Block

Example

With wp-embed

enter image description here

Without wp-embed

If you turn off the wp-embed in the functions, this is how it looks in the front end. enter image description here

How can I get rid of it?

Something to know that this script sits in your footer

<script type='text/javascript' src='http://YOURSITE/wp-includes/js/wp-embed.min.js?ver=6.0.1' id='wp-embed-js'></script>

So you have two options. One is using wp_enqueue_scripts and another is to use the wp_footer.

Using wp_enqueue_scripts

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

Using wp_footer

function deregister_style_scripts() {
    wp_deregister_script( 'wp-embed' );
}
add_action( 'wp_footer', 'deregister_style_scripts' );

How to embed the link

Use the Embed block

enter image description here

Embed doesn't work?

This usually happens when they do not want to embed their content within their site or outside. This can be controlled via X-Frame-Options, there are two directives DENY and SAMEORIGIN

Refused to connect

x-frame-options: DENY

enter image description here

Sorry, this content could not be embedded.

x-frame-options: SAMEORIGIN

enter image description here

Read more

About Embeds: https://wordpress.org/support/article/embeds/
x-Frame-Options: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Frame-Options

Not the answer you're looking for? Browse other questions tagged or ask your own question.