1

It is easy to disable oEmbed on the front end Disable automatic oEmbed of a youtube url within the content, but this leaves us with the editor shows a video (in the case of youtube) where on the front end there will be only a URL.

How can it be disabled on the editor side as well?

1

The quick way to disable oEmbeds would be

add_filter( 'pre_oembed_result', '__return_false' );

If you want to disable it for all external links then try:

/**
 * Disable oEmbeds for external links 
 */
add_filter( 'pre_oembed_result', function( $result, $url, $args )
{    
    if( parse_url( home_url(), PHP_URL_HOST ) !==  parse_url( $url, PHP_URL_HOST ) )
        $result = false;

    return $result;

}, 999, 3 );

This is a modification from a more detailed answer I posted here.

  • hmm, anything more refined then that? will be great if I can still have it working on pages but not on some custom post type that should be associated with basically text only content. – Mark Kaplun May 17 '17 at 11:20
  • You mean how to disable it during post editing in the backend, for a given post type?. We could e.g. check for _POST variables like post_ID, type=embed, action=parse-embed and shortcode, within our pre_oembed_result callback, but then we would need to remove the post type from wp_ajax_oembed_cache() through the embed_cache_oembed_types filter or check GET variables. Sounds hackish. Maybe there are other ways to stop the ajax calls for given post types? – birgire May 17 '17 at 23:02
  • will take a look layer, right now it actually do not work for me and I have no time to check if it is some caching, and it is not a priority, just a nice yo have ... – Mark Kaplun May 18 '17 at 2:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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