[wp-trac] [WordPress Trac] #56780: shortcode block in block-based template part in a classic theme does not get expanded

WordPress Trac noreply at wordpress.org
Fri Oct 4 17:14:57 UTC 2024


#56780: shortcode block in block-based template part in a classic theme does not
get expanded
-------------------------------------------------+-------------------------
 Reporter:  pbiron                               |       Owner:  costdev
     Type:  defect (bug)                         |      Status:  assigned
 Priority:  high                                 |   Milestone:  Future
                                                 |  Release
Component:  Editor                               |     Version:  6.1
 Severity:  normal                               |  Resolution:
 Keywords:  has-testing-info has-screenshots     |     Focuses:
  has-patch has-unit-tests changes-requested     |
  needs-testing early                            |
-------------------------------------------------+-------------------------

Comment (by ecairol):

 For folks out there still having this issue, here's a workaround while the
 patch makes it to core.

 At the top of your template, extract the block HTML to a variable and
 apply `do_shortcode()`:


 {{{#!php
 <?php
 ob_start();
 block_template_part( 'header' );
 $block_header = do_shortcode( ob_get_clean() );

 }}}

 Make sure to include `wp_head()` **after these lines**, so that the proper
 CSS inline styles are embedded on the screen:

 {{{#!php
 <?php
 <head>
   <?php wp_head(); ?>
 }}}

 And then `echo $block_header` to actually render the block where you want
 it.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/56780#comment:78>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list