Dark

Light

Dark

Light

Scroll to top

How to use shortcode with ob_start and ob_end_clean() ?

function callback(){
	ob_start();
	?>
	Content goes here
	<?php
	$output_string = ob_get_contents();
	ob_end_clean();
	return $output_string;
}
add_shortcode('shortcodename','callback');

Now use [shortcodename] like this anywhere in the page or in between the post.

ob_get_contents() will help to tell the actual position of the shortcode.

Author avatar
Amitpal Singh
https://amitpalsingh.com

Post a comment

Your email address will not be published. Required fields are marked *