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.

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

1 Answer 1

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

 
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.