Wrapping php code between opening and closing shortcode in wordpress

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

Read More
<?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.

Related posts

1 comment

  1. The problem you have is you’re outputting the value of myget_info() immediately instead of returning it so it can be used inside do_shortcode().

    Change:

    function myget_info() {
        echo '123';
    }
    

    To:

    function myget_info() {
        return '123';
    }
    

Comments are closed.