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

WordPress oEmbed W3C Validation

The class-oembed.php file reveals some of the available filters regarding the oEmbeds. We can use the oembed_result or oembed_dataparse filters to modify the HTML fetched from Vimeo before it’s cached in the post meta. Here’s an example for the latter: add_filter( ‘oembed_dataparse’, function( $return, $data, $url ) { // Target only Vimeo: if( is_object( $data … Read more

Set wmode attribute to transparent for the embed shortcode to make drop-down menu hover over YouTube embed in Internet Explorer

You can filter the HTML output for oEmbed with oembed_result. Now test the HTTP host of the URL for www.youtube.com and add the parameter. The oEmbed result is cached in a post meta field to avoid too many requests. To update old posts I have added an activation helper that clears those cached content for … Read more

Add wrapper to only youtube videos via embed_oembed_html filter function

$url will contain the full URL to the embed source. E.g.: https://www.youtube.com/watch?v=_UmOY6ek_Y4, so you have to search within $url to see if the provider’s name appears: add_filter( ’embed_oembed_html’, ‘wpse_embed_oembed_html’, 99, 4 ); function wpse_embed_oembed_html( $cache, $url, $attr, $post_ID ) { $classes = array(); // Add these classes to all embeds. $classes_all = array( ‘responsive-container’, ); … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)