2

I run a small site based on wp with user generated content. Users often submit youtube links. And then wordpress automatically converts these links to videos which is unwanted in our case. I need to override this automatic behavior so that the submitted youtube links remains in plain text urls ?

I found out that I could remove the oembed provider itself with something like wp_oembed_remove_provider('http://www.youtube.com/oembed') but I am stumped at how do I use this in my case where $content is the string that contains the url as well as the submitted post content ? The codex page doesnot says much about it. Could someone give me an example of how this can be done.

In other words I need the oEmbed to skip any youtube link/s in content. Also please let me know if there is a better/more efficient way of solving this.

2 Answers 2

4

disable the oembed like below in functions.php :

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

Thanks!

2
  • we need the embed to work for other providers except youtube. How can we do it please ?
    – gurung
    Sep 12, 2015 at 9:28
  • Please try using this will disable your youtube one and rest like Twitter will still work.
    – jas
    Sep 12, 2015 at 9:42
8

The accepted answer didn't work in my case. URLs were still being converted to embeds in the post editor.

By looking at the source of wp-includes/class-wp-embed.php where this stuff is handled, I found that there are some other things at play here:

// Hack to get the [embed] shortcode to run before wpautop()
add_filter( 'the_content', array( $this, 'run_shortcode' ), 8 );

// Shortcode placeholder for strip_shortcodes()
add_shortcode( 'embed', '__return_false' );

// Attempts to embed all URLs in a post
add_filter( 'the_content', array( $this, 'autoembed' ), 8 );

// After a post is saved, cache oEmbed items via AJAX
add_action( 'edit_form_advanced', array( $this, 'maybe_run_ajax_cache' ) );

What fixed the issue for me was disabling these in my theme files like so:

remove_shortcode( 'embed' );
remove_filter( 'the_content', [ $GLOBALS['wp_embed'], 'autoembed' ], 8 );
remove_filter( 'the_content', [ $GLOBALS['wp_embed'], 'run_shortcode' ], 8 );
remove_action( 'edit_form_advanced', [ $GLOBALS['wp_embed'], 'maybe_run_ajax_cache' ] );
3
  • This worked for me. Thanks for providing a full and correct asnwer. Jan 22, 2016 at 15:18
  • After several other solutions I found didn't work for me, this one is what did. Thanks.
    – John Smith
    Sep 28, 2016 at 8:21
  • Yay! After searching for forever, this answer finally worked for me.
    – Pete
    Apr 12, 2017 at 18:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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