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?

1 Answer 1


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!

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.