I have a two part shortcode, with opening and closing shortcodes, in a template file. See example below.
echo do_shortcode('[myshortcode][/myshortcode]');
I see from the Codex that I can do this:
echo do_shortcode('[myshortcode]' . '<div class="anyHTML">Any Text</div>' . '[/myshortcode]');
Is it possible/correct or will it work to do this instead?
echo do_shortcode('[myshortcode]');
$somePHP = possibleWordPressLoopCodeOrOtherPHP;
echo do_shortcode('[/myshortcode]');
I’m wondering about this to see if I can include PHP inside a two part shortcode, possibly a WordPress loop for a CPT or even other PHP code.
You need to have the whole shortcode block inside the
do_shortcode
function. So you could do something like this: