Tag Info

Hot answers tagged

7

No, its not possible. $content_width is a theme-wide constant, and its set in functions.php before any of the query conditionals are set. $content_width is used to determine the intermediate image sizes in image_send_to_editor. The "large" image size will be set to the value of $content_width. If you need to modify those sizes on a per-category basis, you ...


6

Use the oembed_dataparse filter to modify the resulting HTML output by any given oembed call. Example: add_filter('oembed_dataparse','test',10,3); function test($return, $data, $url) { if ($data->provider_name == 'YouTube') { return "<img src='{$data->thumbnail_url}'>"; } else return $return; } Then putting this in a ...


6

I needed just this for a recent project, so here's my plugin! The code should be self-explanatory, but if there are any questions ask away. <?php /** * Plugin Name: oEmbed Featured Image * Plugin URI: http://wordpress.stackexchange.com/q/70752/1685 * Description: Automatically set the featured image if an oEmbed-compatible embed is found in the post ...


5

Those are not really arguments like for YouTube, more of arguments for WordPress itself. One way to handle it would be to access your argument later inside of a filter and modify HTML output. Pass in arguments array: wp_oembed_get( 'http://www.youtube.com/watch?v=', array( 'autoplay' => 1 ) ); And filter: add_filter('oembed_result','oembed_result', ...


5

I'm assuming you are using WordPress' Embeds feature. Generally speaking wp_embed_defaults() gives you the information you need. A look at the source discloses the possibilities you have: 2017 /** 2018 * Create default array of embed parameters. 2019 * 2020 * The width defaults to the content width as specified by the theme. If the 2021 ...


4

The problem: The reason why this isn't working, is this part of the WP_Embed::shortcode() method: if( $post_ID ) { .... cut ... // Use oEmbed to get the HTML $html = wp_oembed_get( $url, $attr ); ... cut ... } When trying to autoembed with the Heartbeat API the $post_ID is null, so wp_oembed_get() is never activated. No Caching: ...


4

WP_oEmbed::data2html() has a filter, oembed_dataparse. You can use this to change the output, based on the extra data which is passed as the second parameter. Something like this for example: add_filter( 'oembed_dataparse', 'wpse17461_oembed_dataparse', 10, 3 ); function wpse17461_oembed_dataparse( $html, $data, $url ) { if ( FALSE !== strpos( $url, ...


4

Two things: WordPress' oEmbed implementation prefers and works better with JSON. To use XML, WordPress needs the simplexml library in PHP to be available. If it's not available, then you'd probably get the results you're seeing. It's getting the XML but can't parse it without simplexml, so... nothing happens. Best way to fix the problem: Stop trying to ...


4

Not entirely sure it is supposed to be used like this, but by analogue with the_content try this: add_filter('the_excerpt', array($wp_embed, 'autoembed'), 9);


3

Building a fake embed shortcode and then calling run_shortcode to do this makes no real sense. Try this instead: echo $wp_embed->shortcode(array(), $my_tour_video); Edit: Additionally, when I use your code on a test page, using that embed, I get no such error as you're describing. If you can come up with a reproducible test case, then it might be ...


3

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 Youtube embeds only. <?php # -*- coding: utf-8 ...


3

It appears I've been hoodwinked by my local setup & accidentally stopping connections to vimeo / youtube. This resulted in the video url appearing as only text. Once my setup was restarted everything appears to be working properly. Sorry for the confabulation.


3

I assume that you're only interested in the first URL that actually succeeds at discovering actual oembed data. The oembed system processes all links it finds, but not every link will have oembed going for it, obviously. The filter you'll want to use is embed_oembed_html and it gets the HTML cached by oembed, the url, any attributes on the embed, and the ...


3

wp-includes/class-oembed.php has a public variable $providers. So you can build a small function to get all of them: function list_oembed_providers( $print = TRUE ) { require_once( ABSPATH . WPINC . '/class-oembed.php' ); $oembed = _wp_oembed_get_object(); $print and print '<pre>' . htmlspecialchars( var_export( $oembed->providers, ...


3

Looking into WordPress Core vimeo is registered like so: '#http://(www\.)?vimeo\.com/.*#i' => array( 'http://www.vimeo.com/api/oembed.{format}', true ), But looking at vimeo API for oEmbed they show their URL without the www. so what you need to do is register vimeo oEmbed correctly: add_action( 'init', 'add_vimeo_oembed_correctly' ); function ...


3

The embed_oembed_html filter runs before an oEmbed resource's HTML is outputted, so you could hook into this and wrap the output in a div as below. I can't think of a simple way of wrapping the other content. add_filter('embed_oembed_html', 'my_embed_oembed_html', 99, 4); function my_embed_oembed_html($html, $url, $attr, $post_id) { return '<div ...


3

Just use the [embed] shortcode around your items. <ul> <li>[embed]http://www.youtube.com/link/to/content[/embed]</li> ...


3

Another method can be like this, On the current post when you save look for youtube video in the content, if found save it to the transient 'videos' and the post_id (for the link to the post later) insted of regex im using parse_url() and parse_str() add_action( 'save_post', 'save_youtube_videos' ); function save_youtube_videos( $post_id ) { $saved = ...


3

I think that a better option will be re-size the video with CSS, supposing you have the container .video_index for the index of videos and .video_single for a single video entry, here is an example. .video_index iframe{ width: 250px; height: 170px; } .video_single iframe{ width: 500px; height: 360px; }


3

Yeah, the old story with (O)embeds and content width. As soon as there is repsonsiveness, the whole system falls apart. A solution, that might be of use is what we do in our themes: /** * Change the embed code, so we can apply awesome css shit * Called by filter "oembed_result" * * @author Hendrik Luehrsen * @since 1.0 * * @param $html string The ...


2

Take out the var_dump. That is debugging code, it's dumping the variable so that you can see what it is. Edit: Okay, I think you're asking the wrong question here, as did the other person in the question that you linked to. Adding additional query args onto the URL being sent to wp_ombed_url() won't cause the oembed system to send them on to the oembed ...


2

Without knowing more about your theme I can only hazard a few guesses. What are you inputting as an excerpt, what is the current output you are seeing for your excerpt, and what is the expected output? Are you seeing the URL show up in the excerpt, or is it being stripped? Oembed Are you being sure to scope in $wp_embed? global $wp_embed; add_filter( ...


2

No extra code needed. Simply include the timestamp parameter onto the YouTube link, with the format of hash t equals number m number s. Or in other words: #t=1m02s The numbers are minutes and seconds. Example of a rickroll pre-fast-forwarded to 1 minute in: http://www.youtube.com/watch?v=dQw4w9WgXcQ#t=1m0s YouTube's oEmbed endpoint seems to handle this ...


2

I'm not sure why that's not working except maybe you need to put the returned stuff in a variable? This is what works for me when I put it in my functions.php file: add_filter( 'embed_oembed_html', 'tdd_oembed_filter', 10, 4 ) ; function tdd_oembed_filter($html, $url, $attr, $post_ID) { $return = '<figure ...


2

You need to set the global $post object to your post. This is done by the loop functions in your theme which is why it works there. WP's oEmbed replaces the URLs during the the_content filter. But it replaces the URLs through two means. The first is a simple regex find and replace for certain URLs such as Google Video or linking directly to a file with a ...


2

Something like this should do the trick and force rel=0 for all YouTube oembed results. add_filter('oembed_dataparse','youtube_force_rel',10,3); function youtube_force_rel($return, $data, $url) { if ($data->provider_name == 'YouTube') { return str_replace('feature=oembed', 'feature=oembed&#038;rel=0', $return); } else { return ...


2

Make a custom plugin for your site, put this code in it. add_filter('oembed_dataparse','oembed_youtube_add_wrapper',10,3); function oembed_youtube_add_wrapper($return, $data, $url) { if ($data->provider_name == 'YouTube') { return "<div class='whatever'>{$return}</div>"; } else { return $return; } }


2

Without even running that code I can see a pretty significant problem. You describe the goal as to "check all my posts to see if there is a embedded YouTube video" but the query is restricted to only one post. And then, you are only attempting to use the very first post in the results (if the query works at all) anyway so there is no way that this is going ...


2

You can try this: add_filter( 'embed_oembed_html', 'custom_youtube_oembed' ); function custom_youtube_oembed( $code ){ if( stripos( $code, 'youtube.com' ) !== FALSE && stripos( $code, 'iframe' ) !== FALSE ) $code = str_replace( '<iframe', '<iframe class="youtube-player" type="text/html" ', $code ); return $code; } to target ...


2

All you need to do use apply_filters. foreach ($video as $vid) { echo '<li>'.apply_filters('the_content',$vid).'</li>'; } It may be more efficient to concatenate a string and then run the filter on the whole thing. $lis = ''; foreach ($video as $vid) { $lis .= '<li>'.$vid.'</li>'; } echo apply_filters('the_content',$lis); ...



Only top voted, non community-wiki answers of a minimum length are eligible