It does not work because the second block does not know what $out is. I did not find how I can handle
[insert_php]
/* do something */
$out = smthing;
[/insert_php]
<html>
/*something */
[insert_php]
echo $out;
[/insert_php]
</html>
Edit: How can I write a for loop, it did not work
[insert_php]foreach($elements as $element){ [/insert_php]
<label class="radio-inline"><input type="radio" name="opt" value=[insert_php]echo $element; [/insert_php] > [insert_php] echo $element; [/insert_php]</input> </label>
[insert_php]}[/insert_php]
The [insert_php]...[/insert_php]
shortcodes are totally separate from each other. The entire body of that tag must be complete and valid PHP code.
You can share the variable by using a global variable. I'd pick a name that's more unique than $out
, to be on the safe side:
[insert_php]
global $MY_CUSTOM_TEMP_VAR;
/* do something */
$MY_CUSTOM_TEMP_VAR = smthing;
[/insert_php]
<html>
/*something */
[insert_php]
global $MY_CUSTOM_TEMP_VAR;
echo $MY_CUSTOM_TEMP_VAR;
[/insert_php]
</html>
You can make a loop inside a single [insert_php]...[/insert_php]
shortcode tag:
[insert_php]
foreach($elements as $element)
echo "
<label class='radio-inline'>
<input type='radio' name='opt' value='" . esc_attr( $element ) ."'>$element</input>
</label>
";
[/insert_php]