Tips

Problems with Shortcodes in Text Widgets

The text widgets of WordPress 4.8 came with a new feature – a HTML editor. That is great for people who want to format their text, but it is also bad news since the TinyMCE editor tends to clean up or reformat the original code. For example, “=>” gets converted into the HTML-safe encoding “=>”, and so the “greater than sign” has no effect anymore on the structure of the HTML page but will be interpreted merely as part of the content. It is clear that this change breaks every code where the “=>” is required literally.

I recently noticed that also shortcode parameters wrapped in double quotes seemed to receive the quotes as part of the text. As a direct result, these quotes stopped doing their job as a wrapper for a text that may contain spaces. For example,

text="Click here!"

now breaks at the space and the parameter “text” receives the value

"Click

instead of the entire Click here!.

There are various possible solutions how to deal with the problem, for example with tooltips (“help pointer”). They don’t, however, help you solve the mentioned problems. I’m afraid that users simply click them away, like Jetpack’s tooltip that tells me about their Twitter widget or the tips for first-time users. Considering the importance of the matter, these notices should be formatted as alerts.

The only solution that makes sense to me now is to return to a text widget that works exactly like before. I tried the Classic Text Widget, and it seems to do it’s job. Similar problems, however, might appear later with WordPress 5.0 when the new editor Gutenberg (presently still a plugin) is scheduled to become the new standard.

Christoph