Forcing oembeds to top of post

you can create custom post meta which contain youtube url
and then

$yt=get_post_meta($post->ID,'youtube_url',true);
if( '' != $yt)
echo $GLOBALS['wp_embed']->autoembed( $yt );

Updated:

If i’m getting correctly then your content contain youtube url any where in it and you want to show them at top regardless there position in content.

jut paste this code in functions.php

add_filter('the_content','ravs_youtube_atTop',1);
function ravs_youtube_atTop($content){
    /* get list of all youtubr urls */
    preg_match_all('#https?://(www\.)?youtube.com/watch.*#', $content, $matches);
    /*replace all youtube url by empty string*/
    $content = preg_replace('#https?://(www\.)?youtube.com/watch.*#','',$content);
    /* return actual content if not youtube url found */
    if( empty($matches[0]) )
        return $content;
    /*insert all youtube embed iframes at top of content*/
    foreach( $matches[0] as $match){
        $content = wp_oembed_get($match).$content;
    }
    return $content;
}

Leave a Comment