Support » Fixing WordPress » Video post format, extra content breaks video embed

  • I am using the content-video.php include to show the latest video post on my homepage. The include only shows the video from the post and not the rest of the content, which works well.

    My problem is, if I add any content (eg – text, another link, etc) after the link to the video in the post, it breaks my video embed on the homepage. The video and text before and after display fine in the actual post.

    Here is the code I have for content-video.php

    <?php if(strlen( get_the_title() ) >0 ): ?>
        <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
    <?php endif; ?>
        $parsedUrl  = parse_url(get_the_content());
        $embed      = $parsedUrl['query'];
        parse_str($embed, $out);
        $embedUrl   = $out['v'];
    <iframe width="385" height="217" src="<?php echo $embedUrl; ?>" frameborder="0" allowfullscreen></iframe>

    And, here is the loop code where I’m including it on the homepage:

            $args = array(
                'post_type' => 'post', // if the post type is post
                'posts_per_page' => 1,
                'tax_query' => array(
                    'taxonomy' => 'post_format',
                    'field' => 'slug',
                    'terms' => 'post-format-video'
            $my_query = new WP_Query( $args );
            <?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
            <div id="latestVideo">
                <?php get_template_part( 'content', 'video' ); ?>
                <a class="more-videos" href="/type/video/">more videos</a>
        <?php endwhile; ?>

    Can anyone spot what I’m doing wrong, or do I need to embed the video in a different way?!

    Thanks for any help.

  • The topic ‘Video post format, extra content breaks video embed’ is closed to new replies.