WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

With shortcodes that have only one attribute, it would be much easier from a content-editing perspective to use, for example, [icon="myicon"] instead of [icon whichicon="myicon"].

Is this possible in Wordpress? Is it problematic?

share|improve this question
up vote 2 down vote accepted

I thought this was a rather good question, so I tinkered with it a little. It seems as though the catch to using the direct method ([icon='myicon']) vs using an attribute is that with the direct method, you cannot use spaces as it will split to separate attributes, even if you use quotation marks, and the quotation marks and equals sign are considered part of the value. For example: a print_r( $atts ) on [dev_dump http://example.com/test.jpg] returns Array ( [0] => http://example.com/test.jpg ), whereas a print_r( $atts ) on [dev_dump='my icon'] returns Array ( [0] => ='my [1] => icon' ). That said, however, [dev_dump foo='bar' http://example.com/test.jpg] does give you Array ( [foo] => bar [0] => http://example.com/test.jpg ), so as long as there is only ONE unlabeled value, you should be pretty safe to use that method, as you can just use $atts[0]. Be careful with setting up defaults, as I can see that becoming tricky and buggy relatively quickly.

Thanks for asking a great question, really made me think!

share|improve this answer

Your Answer


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.