Shortcodes are not working in page templates
-
I downloaded WordPress 5.9-RC1 to try the new full site editor using the “WordPress Beta Tester” plugin, and while I was testing it, I noticed that the shortcode block does not transform the shortcodes in the page template. (Works fine in the actual page/post content.)
I created a new plugin and I added the following testing code to it:
add_shortcode('note', 'tt_test_note'); function tt_test_note($atts, $content = null) { ob_start(); ?> <div class="note" style="margin: 30px 0; padding: 27px 40px; background: #fcf3dc; border-radius: 5px;"> <p><?php echo $content; ?></p> </div> <?php return ob_get_clean(); }
<h2>Environment:</h2>
1. WordPress 5.9-RC1
2. Active theme: Twenty Twenty-Two Version: 1.0
3. Active plugins: only the shortcode plugin that has the code above and nothing else
4. PHP: 7.2.34-28+ubuntu18.04.1+deb.sury.org+1<h2>What’s the issue?</h2>
When using the shortcode[note]test[/note]
in Gutenberg’s own shortcode module works in the actual page, but not in the template editor.<h2>How to reproduce the problem?</h2>
- Create a new plugin and add the code mentioned above
- Go to Appearance > Editor
- Click on the WordPress icon at the left site
- Select Templates > Page
- Add a new shortcode block above Post title (https://imgur.com/5lFPgtE)
- Write this code there:
[note]test[/note]
- Save the template
- Create a new page
- Add a new shortcode block and write the same shortcode there (https://imgur.com/5lFPgtE)
- Save the page and check it
You’ll see the
[note]test[/note]
code is displayed above the post title, but the yellow block shows correctly up below.<h5>Note</h5>
The same shortcode works if I place it into the “Header” or “Footer” part.Playing around with it more, it seems the shortcode starts working after I create a template part from the whole section. Still weird that it does not work by default.
- The topic ‘Shortcodes are not working in page templates’ is closed to new replies.