Remove WordPress oEmbed Related Items

oEmbed provides an easy way to embed content from one site to another. You're probably familiar with it on sites like YouTube and Twitter. But what if you don't want other sites embedding your stuff? In that case, this snippet is for you.

This snippet will disable some oEmbed-related functionalities. Remove the REST API endpoints, oEmbed auto discovery, and oEmbed-specific JavaScript from the front-end and back-end. Just add these lines to the functions.php of your WordPress theme. If you want to remove everything related to oEmbed, grab Disable Embeds from the WordPress plugin directory. The plugin will remove rewrite rules related to embeds, Tiny MCE plugins, and more.

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

// Turn off oEmbed auto discovery.
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 JavaScript from the front-end and back-end.
remove_action('wp_head', 'wp_oembed_add_host_js');

Comments  Leave a Reply

  1. Thank you, exactly what I needed because Linkedin uses oembed for sharing links, so it always displayed internal WP title instead of og:title. Just wasted an hour figuring out until this saved me!

    1. Glad it helped, Tobiv 🙂

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our privacy policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

WordPress Launch Checklist

The Ultimate WordPress Launch Checklist

We've compiled all the essential checklist items for your next WordPress website launch into one handy ebook.
Yes, Send Me the Free eBook!