Putting php inside an echo php shortcode

You’re close but not quite.

do_shortcode expects a string so give it one!


If function() returns a string you can

echo do_shortcode( '[shortcode]' . function() . '[/shortcode]' );

If function() directly outputs, you can capture its output using output buffering

//start the buffer
ob_start();

function();  //i.e pdf_print_popup();

//store out output buffer
$string = ob_get_contents();

//clear the buffer and close it
ob_end_clean();

and then use the string we stored

echo do_shortcode( '[shortcode]' . $string . '[/shortcode]' );