Repository navigation
Add a filter to leave shortcode content unformatted in wpautop - #16275
Vedant-Gandhi wants to merge 4 commits into
Conversation
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. Props Bot commandsYou can trigger Props Bot actions by commenting on this PR:
|
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
Description
Adds an opt-in
no_autop_shortcodesfilter towpautop(). Shortcodes listed there, including the content between their opening and closing tags, are left as written instead of getting<p>and<br />tags.It is inspired from the precedent of
no_texturize_shortcodesfilter. The default is an empty array, so nothing changes unless a plugin or theme opts in:Why:
wpautop()runs beforedo_shortcode(), so a shortcode callback receives content that has already been paragraphed. In the ticket's example, a[code]shortcode wrapping PHP arrives with<p>and</p>inserted into the code. Changing this for every shortcode would break the ones that expect paragraphed text, and movingdo_shortcode()earlier would break many plugins (see comment 12 on the ticket), so this is opt-in.How:
get_shortcode_regex()and swaps each match for a placeholder, the way<pre>blocks are handled.[[code]]) are skipped, as indo_shortcode_tag().<pre>blocks are restored.[.Notes:
wpautop()is affected.<pre>inside a protected shortcode ends up nested in a<p>.Tests are located in
tests/phpunit/tests/formatting/wpAutop.php. To run tests, execute the following command:Trac ticket: https://core.trac.wordpress.org/ticket/6984
Use of AI Tools
AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Sonnet 5.5
Used for: Investigating the ticket, drafting the implementation and tests, and writing this description. I reviewed the diff, ran the changes, and edited and take responsibility for the final code.