0

I'm working on creating a shortcode to embed locally hosted Quicktime movies, but I can't seem to get the default attributes to stick. Here's what I'm working with, can anyone spot anything obviously wrong? The result gives me no value for an unspecified attribute at all (in this case height/width), rather than the desired defaults of 480 and 320. If specified, it works as intended.

<?php
function quicktime_embedder( $atts, $content = null ) {
    extract( shortcode_atts( array(
        'url' => '#',
        'width' => '480',
        'height' => '320'
    ), $atts ) );

    return '<object classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B"
                codebase="http://www.apple.com/qtactivex/qtplugin.cab" height="300" width="500">
                <param name="src" value="http://www.yoursite.com/video/video1.mov">
                <param name="autoplay" value="false">
                <param name="controller" value="true">
                <param name="type" value="video/quicktime" height="'.$atts[height].'" width="'.$atts[width].'">
                <embed src="'.$atts[url].'"
                     height="'.$atts[height].'" width="'.$atts[width].'" autoplay="false" type="video/quicktime"
                 pluginspage="http://www.apple.com/quicktime/download/">
            </object>';
}

add_shortcode( 'quicktime', 'quicktime_embedder' );

?>

1 Answer 1

0

extract takes and associative array and explodes it out in variables that reflect the array key names. $atts['height'] would just be $height, in other words.

The relevant two lines of your code would become:

<param name="type" value="video/quicktime" height="'.$height.'" width="'.$width.'">
<embed src="'.$url.'" height="'.$height.'" width="'.$width.'" autoplay="false" type="video/quicktime" pluginspage="http://www.apple.com/quicktime/download/">

If you did still want to use the indexing, make sure you surround array keys with quotes: $atts['height'] not $atts[height]. Replace extract:

$atts = shortcode_atts( array(
        'url' => '#',
        'width' => '480',
        'height' => '320'
    ), $atts )
1
  • Perfect! I didn't understand extract correctly. That got me exactly what I needed, thank you so much! Commented Aug 29, 2011 at 13:05

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.