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 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?

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.

share|improve this question

1 Answer 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.

share|improve this answer
    
Thank you.I just want to use it in my theme.Extract the url part or maybe search that shortcode in a post and then display it.In brief,I want to show the shortcode in php files.OK...it maybe be a bit confusing –  Joshua L Jul 20 '13 at 22:40
    
Very nice,I get the idea.Thank you so much!!! –  Joshua L Jul 20 '13 at 22:40

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.