I need to put an include inside a shortcode. Can any one help me to do it, please?
Example:
echo do_shortcode( '[student]' . include 'incMac.php' . '[/student]' );
I need to put an include inside a shortcode. Can any one help me to do it, please?
Example:
echo do_shortcode( '[student]' . include 'incMac.php' . '[/student]' );
You won’t be able to concatenate an include as it doesn’t return a string. What you could do is store that include content in a variable, and then concatenate.
ob_start();
include 'incMac.php';
$include_content = ob_get_clean();
echo do_shortcode( '[student]' . $include_content . '[/student]' );
ob_start
tells php to store the output from the script in an internal buffer, instead of printing it.
ob_get_clean
returns the content of the buffer at the moment and deletes it, turning off the output buffering. We store this content in the $include_content
variable, which can be concatenated.