1

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.

3

disable the oembed like below in functions.php :

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

Thanks!

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

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' ] );
  • This worked for me. Thanks for providing a full and correct asnwer. – sidonaldson Jan 22 '16 at 15:18
  • After several other solutions I found didn't work for me, this one is what did. Thanks. – John Smith Sep 28 '16 at 8:21
  • Yay! After searching for forever, this answer finally worked for me. – Pete Apr 12 '17 at 18:27

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.