wpautop() when shortcode attributes are on new lines break args array

Ok, I’ve never seen a shortcode done in this way so I threw together a bit of code to test your scenario. And I get the same results with code that works just fine with the standard shortcode format.

Standard Shortcode Format

[shortcode name1=”value1″ name2=”value2″]

I don’t believe this is a result of wpautop(), but a result of the way the shortcode attributes are parsed. Look at the example above and you’ll see that the only unquoted whitespace is used to separate the shortcode and the name=>value pairs (i.e. no spaces between the name and the ‘=’, only one space between each name=>value pair). In this context the <br/> is also considered whitespace.

I’ve not dug in to the particular internals of shortcode parsing so I can’t offer a suggestion on a a hook or filter that would help. Perhaps another user here has some ideas on that.

If you must format your shortcode like you have it I think you’re going to have to write custom code to parse the array that’s passed to your shortcode function. All the values are there so you should be able to piece them back together.

Another option might be to provide a form for the end-user to enter the values then populate the shortcode in your content.

An update to my answer

Something about my answer was bugging me so I looked again. And you are correct wpautop() is having an effect on the output of the page. But I don’t think it is the cause of your shortcode problems.

Leave a Comment

error code: 523