How to include php file between two shortcode?

108 views Asked by At

i want to include another php file "1.php" in my php file "my.php" between two shortcode [restrict] and [/restrict].

I try this codes but the answer did not work

 <?php echo do_shortcode( '[restrict]' . include '1.php' . '[/restrict]' ); ?>

Plese

1

There are 1 answers

3
nibnut On BEST ANSWER

I suggest you use the output buffer functions:

ob_start
include('1.php');
$file_content = ob_get_contents();
ob_end_clean();
echo do_shortcode( '[restrict]' . $file_content . '[/restrict]' );

Hope this helps!