0

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.

1 Answer 1

1

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');
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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