WordPress – How to disable TinyMCE auto-embed of URL’s (YouTube/Twitter/Facebook etc)

WordPress 4.4 introduced a new feature for the WYSIWYG editor (TinyMCE) – auto-embedding of URL’s added to the editor content.

With this feature URL’s for approved websites added to the content will automatically be loaded by the editor and converted to preview.

For example, pasting a YouTube link into the content area would automatically turn into a preview of the video:

https://www.youtube.com/watch?v=q4y0KOeXViI

And a link to a WordPress plugin:

https://wordpress.org/plugins-wp/akismet/

Akismet

This isn’t suitable for everybody, so if you need to disable this feature you can use the following PHP code.

If you’re not sure where to place this code I highly recommend you read How to create a WordPress plugin for your custom functions.

function disable_embeds_code_init() {

// 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-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' );

// Remove filter of the oEmbed result before any HTTP requests are made.
remove_filter( 'pre_oembed_result', 'wp_filter_pre_oembed_result', 10 );
}

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

Was this article helpful?

Related Articles