Disabling Embeds in WordPress Posts and the Visual Editor

Disabling Embeds in WordPress Posts and the Visual Editor

The newer versions of WordPress make it easy to share all kind of “active” content on your blog. “Passive” content refers to standard texts and images that don’t change or respond to user input. Active content could be anything from a video, or a quiz. In the past, we had to dabble in HTML or Javascript in the “Text” tab of the visual editor (previously called “HTML”). These days however, all we need to do is post a link.

Automatic Content Embedding

If you want to post a youtube link on your blog for example, all you need to do is paste the link to the video into the visual editor. When you do this, two things will happen. First, the link will be automatically converted into a video within the visual editor itself. Here’s a screenshot of what it looks like:

You don’t need to do anything other than paste in the link. The second effect is that this will also reflect in the final post. Here’s a preview:

Previous versions of WordPress gave us an option that allowed us to modify this behavior. But as of version 3.5, that was removed in favor of the default behavior we have today. However using filters and plugins, we can still revert this so that WordPress only shows us the URL instead of the actual content. Here’s how.

Removing Youtube Embeds in the Final Post and Preview

There can be many reasons why you don’t want stuff to be automatically embedded in your posts. It might be a video that you don’t want associated with your site. Or you might have a bunch of URLs that you want to share and don’t want your entire post to be overrun with videos and look like spam. Or maybe it just doesn’t fit the layout of your site. Whatever the reason, you can remove the embedded active content on your final post by adding the following code to your functions.php or wherever you place your custom PHP code:

remove_filter( 'the_content', array( $GLOBALS['wp_embed'], 'autoembed' ), 8);

If you don’t know how to add code to WordPress, here’s an easy step by step tutorial to help you learn. Adding the above code to WordPress will make it display only URLs in the final post. Here’s what the above example looks like now:

Now you can add as many URLs as you want one after the other, without crowding up your page!

Removing Embeds in the Visual Editor Preview

The above line of code will have no impact on the visual editor however. That is controlled by another subsystem entirely. It depends on the tinymce software which powers the WordPress visual editor. To disable automatic embedding of content, we need to prevent a plugin called “wpview” from loading. To do that, we hook into the “tiny_mce_pluings” filter and subtract it from the list of plugins. Here’s the code to do that:

function disable_visual_editor_embeds( $plugins ) {
    return array_diff( $plugins, array('wpview') );
}
add_filter( 'tiny_mce_plugins', 'disable_visual_editor_embeds' );

When activating this code on your website, your visual editor will also start displaying only the URLs instead of the embedded content. Here’s a screenshot:

Disabling Embeds in WordPress

And that’s it! These two snippets of code will prevent all embeddings on your site – whether you’re writing a post or publishing it. If you want an easier way without embedding code, there’s a convenient plugin called “Disable Embeds”. It essentially does the same thing as the above, but also removes the Javascript files associated with the embeds which might make your site a little bit faster.

Both methods are easy and effective.

Leave a Reply

This Website is Hosted by

Powered by RamNode

Disclosure: We receive a compensation from some of the companies whose products or services are presented on our website.