Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have written a short code to display a video off of amazon, and it works. However it is not being placed as expected on the page. I have put the shortcode after the <!--more--> tag but the video displays before the excerpt ruining the layout of the page-of-excerpts.

The page is entered like this:

A few random paragraphs of content
<!--more-->
[amazon_video file="file.flv"]

The shortode is written like so

function amazon_video($atts){
    extract(
        shortcode_atts(
            array(
                'file' => $file
            ), 
            $atts 
        ) 
    );
    $url = get_bloginfo('url');
    ?>
    <embed
        src='<?php echo $url; ?>/jwplayer/player.swf'
        name='player'
        width='640'
        height='480'
        bgcolor='#000000'
        allowscriptaccess='always'
        allowfullscreen='true'
        flashvars='file=<?php echo $file; ?>
                    &streamer=rtmp://xxxxxxxxxxxxx.cloudfront.net/cfx/st
                    &provider=rtmp'
        autoplay="false"
    />
    <?php
}

add_shortcode('amazon_video','amazon_video');

The page in question is here incase you wanted to have a look but you may run into some member permissioning.

Essentially, the video is being called last and below the excerpt but is being displayed first and above the excerpt.

share|improve this question

1 Answer 1

up vote 1 down vote accepted

Had a bit of a brain wave and thought I would capture the output and return it in the function. Turns out it fixed the problem so the final code ended up looking like this:

function amazon_video($atts){
    extract(
        shortcode_atts(
            array(
                'file' => $file
            ), 
            $atts 
        ) 
    );
    $url = get_bloginfo('url');

    $return = "<embed
        src='".$url."/jwplayer/player.swf'
        name='player'
        width='640'
        height='480'
        bgcolor='#000000'
        allowscriptaccess='always'
        allowfullscreen='true'
        flashvars='file=".$file."
                    &streamer=rtmp://xxxxxxxxxxx.cloudfront.net/cfx/st
                    &provider=rtmp'
        autoplay='false'
    />";
    return $return;
}

add_shortcode('amazon_video','amazon_video');
share|improve this answer
    
can't accept my own answer for two days so will do then @mods –  Joshua Mar 6 '12 at 4:11

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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