WordPress / twentytwentytwo

Twenty Twenty-Two, the default WordPress theme that will launch with WordPress 5.9.
404 stars 92 forks source link

Shortcode widgets are not rendered if add them outside of Header or Footer blocks #280

Closed ianlin closed 2 years ago

ianlin commented 2 years ago

Describe the bug

This was discovered while I was doing compatibility tests for WordPress 5.9 and one of our plugin woocommerce/woocommerce-product-finder.

When adding widgets using shortcodes in FSE, if I add the shortcodes outside of the Header or Footer blocks, the widgets are not rendered on the front end.

It's originally reported in 30-gh-woocommerce/woocommerce-product-finder, but seems it's related to the theme itself rather than the plugin.

To Reproduce

Steps to reproduce the behavior:

  1. Install WordPress 5.9-beta1 and WooCommerce 6.0.0-rc.1
  2. Use the theme Twenty Twenty-Two
  3. Install WooCommerce plugin
  4. Go to Appearance -> Editor beta
  5. Add a shortcode block outside of the Header or Footer blocks. See screenshots for more information
  6. Enter short code [woocommerce_cart]
  7. Save the update in the editor
  8. Go to the front end, the text of the shortcodes are displayed

Expected behavior

A WooCommerce cart widget should be displayed.

Screenshots

Full Site Editing the Twenty Twenty-Two Theme Home Page

image

image

Front End Display Twenty Twenty-Two Theme Home Page

image

Device:

Andrew-Starr commented 2 years ago

It's not an issue with the theme.

It is a more general issue with Gutenberg/FSE, in that shortcodes do not work when added to a template (e.g. page, single etc), and only work when the shortcode is inside a tempate-part (e.g. header or footer).

Templates such as page can contain other template-parts besides header and footer, and the workaround is to first add a custom template-part in the page template, then add the shortcode inside the custom template-part.

I'm not sure if this is a bug or whether this is intended behaviour, or just how FSE was always intended to work regarding shortcodes.

kjellr commented 2 years ago

Yeah, I don't believe this is due to anything in the theme. I suggest you add some notes to the Gutenberg issue here, which seems to describe a similar problem: https://github.com/WordPress/gutenberg/issues/35258

ianlin commented 2 years ago

@Andrew-Starr and @kjellr

Thanks for the info, I'm not that familiar with all that themes, FSE, etc, still learning. It makes more senses to report this in Gutenberg repo. Cheers! 😄

Closing this as this issue (or feature) is not related to the theme itself.