Since Wordpress 2.9, wp_oembed_get function has been included.
Example:
<?php $embed_code = wp_oembed_get($url); ?>
Here is the link to the function, to get the embeds:
Domanda
I'm trying to get the first embed url from the post. I know wordpress auto-embeds them but can't find a method to just get the embeds.
$urls = array();
$p = get_post();
preg_match('@https?://(www.)?(youtube|vimeo)\.com/(watch\?v=)?([a-zA-Z0-9]+)@im', $p->post_content, $urls);
echo wp_oembed_get( $urls[0] );
Soluzione
Since Wordpress 2.9, wp_oembed_get function has been included.
Example:
<?php $embed_code = wp_oembed_get($url); ?>
Here is the link to the function, to get the embeds:
Altri suggerimenti
This function will return the first [embed]
shortcode:
function sofa_get_embed_shortcode($content) {
preg_match('/\[embed(.*)](.*)\[\/embed]/', $content, $matches);
return $matches;
}
Pass $post->post_content
as the $content
variable, and you'll receive an array of the [embed]
shortcodes found.