1

I have the following shortcode:

[video width="400" height="400" mp4="http://xxxx.xxxx.xxx/uploads/2014/06/Facebook.mp4"][/video]

I need to get every single atts a single variable, I mean, I need something like this

$width = 400
$height = 400
$file = http://xxxx.xxxx.xxx/uploads/2014/06/Facebook.mp4

does anybody have done something like this before? (I'm very newbie in WP)

3
  • 3
    Have you read the attributes section of the Shortcode API?
    – Milo
    Commented Jul 2, 2014 at 22:17
  • Yes, I have read that section, but it described how to create and populate atts, and I need to get every single value, I think I will need to create my own function to split the atts
    – maverickcr
    Commented Jul 2, 2014 at 22:45
  • 2
    I think you need to read it again.
    – vancoder
    Commented Jul 2, 2014 at 23:07

2 Answers 2

2

Straight from the Shortcode API page on the Codex:

The raw $atts array may include any arbitrary attributes that are specified by the user.

That is to say, the $atts parameter passed to your shortcode callback function contains all the attributes in an associative array.

-2

I think you are looking for the PHP function extract()

function your_shortcode_callback( $atts ) {

    // compare incoming $atts against defaults and extract out 
    extract( shortcode_atts( array(
        'width'         => '12',
        'height'        => '4',
        'file'      => ''
    ), $atts ) );

    if( ! $file )
        return '';

    // do something with the $width, $height, and $file variables

}
4
  • 3
    extract is bad, don't use it.
    – Milo
    Commented Jul 3, 2014 at 0:38
  • That's the first I've heard of that. Thanks for the link. Still seems more like it is annoying and not truly "bad". Commented Jul 3, 2014 at 2:21
  • The thing is that I'm trying to get the $atts of an existing shortcode, I'm not trying to build a shortcode, what I have read about shortcode_atts is that extract(shortcode_atts....) works to merge the array of the existing $atts with a new array of $atts. The idea is that I have to post a comment, and that comment may have a video, the video comes in a shortcode, the problem is that I have to use a flash video player instead of the html5 player, and I have to pass the video url, width and height to work with this video player, so what I need is to split the shortcode.
    – maverickcr
    Commented Jul 3, 2014 at 19:31
  • You should edit your question then because that wasn't clear. It sounds like you need to unregister the existing shortcode and then add your own... unless the shortcode has a filter you can use to modify the output. Commented Jul 4, 2014 at 15:43

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.