Opened 2 years ago
Closed 2 years ago
#57351 closed defect (bug) (duplicate)
Escaped Shortcodes don't work in Block themes
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | |
Component: | Themes | Keywords: | has-testing-info |
Focuses: | Cc: |
Description
The WordPress Shortcode API supports escaping of Shortcodes, by wrapping them in extra square brackets, like [[shortcodetag]]
, so that the Shortcode is printed as text instead of being evaluated.
This is not working in Block themes, it appears.
To reproduce this:
- Set up a normal WordPress site, e.g. using trunk.
- Choose a block theme, like Twenty Twenty-Three.
- Add a simple test plugin that adds a Shortcode, like
<?php /* Plugin Name: Shortcode Test Description: Shortcode Test Version: 1.0 */ add_shortcode( 'test', 'shortcode_test' ); function shortcode_test( $atts, $content ) { return 'Just a test'; }
- Add a new post or page, with this test content:
This is an escaped Shortcode: [[test]] . Here, it's evaluated: [test] .
- Note how after saving, when viewing the page, the escaped Shortcode is also evaluated.
- Repeat this with classic theme, like Twenty Twenty-One.
- Note how the escaped Shortcode is properly shown as text.
Change History (5)
#2
@
2 years ago
Ah, it looks like the issue with Twenty-Twenty One shown during testing is because it uses the_excerpt()
on the home page, which doesn't appear to escape shortcodes. Ignore that part of the reproduction report above, but the lack of escaping in block themes was verified 👍
#3
@
2 years ago
Looking into this more, it appears that when using a block theme, do_shortcode()
is hooked to the_content
twice. The first run renders a literal [test]
, and the second run evaluates it.
Adding this to the top of do_shortcode()
shows that when limited to only one run on the_content
, the shortcode is correctly escaped:
<?php if ( doing_filter( 'the_content' ) && wp_get_theme()->is_block_theme() ) { static $did_block_theme_the_content = false; if ( $did_block_theme_the_content ) { return $content; } $did_block_theme_the_content = true; }
Reproduction Report
This report validates that the issue can be reproduced.
Environment
Expected Results
Actual Results
Notes