I’m using shortcodes for a toggle element and I would like to put the output for the following code inside this toggle element.
<?php
function myget_info(){
echo '123';} ?>
The code i am using for the toggle and my function is
<?php echo do_shortcode( '[vc_toggle title="Toggle title"]' . myget_info() . '[/vc_toggle]' ); ?>
However when I use the above, the output from my function, appears on top of my toggle rather than inside my toggle.
The problem you have is you’re outputting the value of
myget_info()
immediately instead of returning it so it can be used insidedo_shortcode()
.Change:
To: