I want to display (on the home page) only the youtube video (or vimeo) of a sticky post.

I found this code from

/*Sticky list variables en page d'accueil*/
function wpb_latest_sticky() { 

/* Get all sticky posts */
$sticky = get_option( 'sticky_posts' );

/* Get the 5 newest stickies (change 5 for a different number) */
$sticky = array_slice( $sticky, 0, 1 );

/* Query sticky posts */
$the_query = new WP_Query( array( 'post__in' => $sticky, 'ignore_sticky_posts' => 1 ) );
// The Loop
if ( $the_query->have_posts() ) {
$return .= '<ul>';
while ( $the_query->have_posts() ) {
$return .= '<li><a href="' .get_permalink(). '" title="'  . get_the_title() . '">'     . get_the_title() . '</a><br />' . get_the_content(). '</li>';

$return .= '</ul>';

} else {
// no posts found
/* Restore original Post Data */

return $return; 

add_shortcode('latest_stickies', 'wpb_latest_sticky');

I have so 2 issues:

  • it will display all the content of the post.
  • the youtube video is show as a link, wp not embed the video directly into the homepage.

Any help would be apreciate.

Many thanks


When you call get_the_content() some filters aren't applied like they would with the_content() so if you want your content to be formatted you have to use the following: $my_content = apply_filters( 'the_content', get_the_content() )

If you want to extract the youtube video out of your content you'll have to detect the youtube link with a regex and then apply the filter on the extracted url.


  • Thank you Mathieu i will investigate further on this way
    – Neoseeyou
    Jun 16 '15 at 12:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.