Block markup generally works in included PHP files. I prefer to use PHP includes in many cases as I can do more interesting things with it than I can with a template file (.html). I've just encountered an example where a macro works in a template file but not a PHP include: if I have the following content in a template file (let's call it templates/single-custom.html),
<!-- wp:shortcode -->[ai_playlist id="2276"]<!-- /wp:shortcode -->
the shortcode renders on the front end for the 'custom' post type. If, however, I have the following content in the template file,
<!-- wp:pattern {"slug":my-theme/hidden-my-include"} /-->
and then in patterns/hidden-my-include the same content,
<!-- wp:shortcode -->[ai_playlist id="2276"]<!-- /wp:shortcode -->
the output is the string,
[ai_playlist id="2276"]
I've fiddled with it a bit, and also tried,
<!-- wp:shortcode --><?php echo do_shortcode('[ai_playlist id="2276"]'); ?><!-- /wp:shortcode -->
in the include file, but it still just echoes the shortcode string (I've also tried do_shortcode without the wrapping echo).
Any ideas?
Edit:
I am going to leave the accepted answer, but others should know that the solution may or may not reintroduce a security vulnerability identified with rendering shortcodes in Block Themes: https://core.trac.wordpress.org/ticket/58333
Note that a workaround outlined by a user in the above-linked Trac issue is as follows (place in functions.php, or another included file in theme or plugin),
/*
Plugin Name: Fix shortcode
Plugin URI:
Description: Restore shortcode support on block templates https://core.trac.wordpress.org/ticket/58333
Author: Anderson Martins, Gabriel Mariani
Version: 0.2.0
*/
function parse_inner_blocks(&$parsed_block)
{
if (isset($parsed_block['innerBlocks'])) {
foreach ($parsed_block['innerBlocks'] as $key => &$inner_block) {
if (!empty($inner_block['innerContent'])) {
foreach ($inner_block['innerContent'] as &$inner_content) {
if (empty($inner_content)) {
continue;
}
$inner_content = do_shortcode($inner_content);
}
}
if (isset($inner_block['innerBlocks'])) {
$inner_block = parse_inner_blocks($inner_block);
}
}
}
return $parsed_block;
}
add_filter('render_block_data', function ($parsed_block) {
if (isset($parsed_block['innerContent'])) {
foreach ($parsed_block['innerContent'] as &$inner_content) {
if (empty($inner_content)) {
continue;
}
$inner_content = do_shortcode($inner_content);
}
}
$parsed_block = parse_inner_blocks($parsed_block);
return $parsed_block;
}, 10, 1);