1

Whatever WP function assembles the $att array from the [myShortcode att1="..." att2="..." ...] string uses the " character to delimit the data. However, the and the characters seem to be read as text, not delimeters; and their use in place of " can lead to shortcode errors.

In theory, there shouldn't ever be a problem because and are not characters on the qwerty keyboard, and so would not be encountered with manual entry. Yet, cutting and pasting from sources that use and allow for their inclusion (and there should be error checking for that situation). For example, the page The Beginner’s Guide to Writing Your Own Custom Shortcode says that [helloworld name=”Bob”] outputs Hello Bob!, which is not the case because the webpage cutely styled " into . Cutting and pasting [helloworld name=”Bob”] outputs Hello ”Bob”!; and [helloworld name=”Bob Smith”] outputs Hello ”Bob!, since the space between Bob and Smith is read as a delimeter and the array says that [name] = "Bob and that [0] = Smith.

Doing a preg_replace on the shortcode string before it is parsed into the $atts array seems like the best way to prevent errors. The question is where to do that.

1

1 Answer 1

0

shortcode_atts_{$shortcode} seems to be the WordPress filter you need. https://developer.wordpress.org/reference/hooks/shortcode_atts_shortcode/

It is used in the shortcode_atts() function: https://developer.wordpress.org/reference/functions/shortcode_atts/

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.