How to parse this shortcode?

I have a shortcode like this [soundcloud url="http://api.soundcloud.com/tracks/67658191" params="" width=" 100%" height="166" iframe="true" /]

How can I get the content of the URL part or extract the whole shortcode in a post and then display it?

Read More

do_shortcode doesn’t help a lot.

I want to use that shortcode in my theme and since the URL part is dynamic I have difficulty of having it display dynamically.

Related posts

1 comment

  1. shortcode_parse_atts will give you managable information.

      $atts = shortcode_parse_atts(
        '[soundcloud url="http://api.soundcloud.com/tracks/67658191" params="" width=" 100%" height="166" iframe="true" /]'
      );
    

    You will get an array that looks like this:

    array(7) {
      [0]=>
      string(11) "[soundcloud"
      ["url"]=>
      string(41) "http://api.soundcloud.com/tracks/67658191"
      ["params"]=>
      string(0) ""
      ["width"]=>
      string(5) " 100%"
      ["height"]=>
      string(3) "166"
      ["iframe"]=>
      string(4) "true"
      [1]=>
      string(2) "/]"
    }
    

    You can the do something like:

      var_dump($atts);  // dump everything
      echo $atts['url']; // echo just the URL
    

    I don’t understand the context you want to use this in. I think you’ve left out a fair bit of explanation.

Comments are closed.