Displaying oEmbed errors?

Not possible with current code. WP_oEmbed object goes extra mile (more like miles) to sanitize input so it is either html or boolean false. All errors with fetching are discarded on output, there are no filters in there and only error (hardcoded) it handles is 501 not implemented. Earliest you can mess with this is … Read more

How to get the oEmbed type (audio, video, image etc.)?

I wonder if you mean this: add_filter( ‘oembed_dataparse’, function( $return, $data, $url ) { // Target only ‘video’ type: if( is_object( $data ) && property_exists( $data, ‘type’ ) && ‘video’ === $data->type ) { // do stuff } return $return; }, 10, 3 ); where we target the video type response from the oEmbed service, … Read more

How to oEmbed from custom field, responsive to container size and responsive

I completed the task with fitvids.js by using the plugin FitVids for WordPress. Chris Coyier describes the integration with WordPress in his screencast Integrating FitVids.js into WordPress (on YouTube). My custom field name is video_url. I used the following code in my template: <?php if (!((get_post_meta($post->ID, ‘video_url’, TRUE))==”)) { echo wp_oembed_get( get_post_meta($post->ID, “video_url”, true) ); … Read more

Enqueue script only if page has an oembed

Well the first thing to consider is that the wp_enqueue_scripts action hook fires before the filters on the page/post content are run. So I would add a function to the wp action hook and test the content for oembeds there. add_action( ‘wp’, ‘your_oembed_test_function’ ); function your_oembed_test_function(){ //earliest reliable hook to get $post variable global $post; … Read more

How to use get_media_embedded_in_content function

The get_media_embedded_in_content() function is a handy helper function, though it doesn’t seem to be used in the core (ver. 4.2.2). Regular expression: To understand the get_media_embedded_in_content() function, we must understand the following regular expression: #<(?P<tag>video|audio|object|embed|iframe)[^<]*?(?:>[\s\S]*?<\/(?P=tag)>|\s*\/>)# There are many online regular-expression tools to help us with that. Like this one: Debuggex demo We note that it’s … Read more

How to add new embed handler not supported by oembed

Registering a custom embed handler Here’s an example how we can use the wp_embed_register_handler() function in your case: /** * Register an embed handler for myvi videos */ add_action( ‘init’, function() { wp_embed_register_handler( ‘myvi’, ‘#http://www\.myvi\.ru/watch/([a-zA-Z0-9_-]+)$#i’, // <– Adjust this to your needs! ‘myvi_embed_handler’ ); } ); Here we constructed the regular expression in a way … Read more

Detecting Embed URLs Within post_content

OK, got it. I just dug around in wp core a bit and found the function they use to grab autodetcts. WP uses the php preg_replace_callback function within the WP autoembed function. Here is the code, as seen in wp-includes/class-wp-embed.php: /** * Passes any unlinked URLs that are on their own line to {@link WP_Embed::shortcode()} … Read more

Problems using WP’s oembed function + Instagram + AJAX

Instagram has changed its embed code from being just an iframe to a bunch of HTML and a JS script. Very inelegant, but nothing we can do. This setup, of course, fails when called through AJAX since the JS file that’s part of the HTML does not run. Thankfully there is another official way to … Read more