1

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.

3

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.

  • 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
  • @s_ha_dum, is there any function to reverse this behaviour ? I have an array with shortcode name in tag key and attributes in attr key. I want to create a shortcode strign so that I can use do_shortcode with it later. I can manually do it, but wanted to know if there's a function in core. – Jashwant Mar 22 '17 at 8:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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