How to use ob_start and ob_get_clean in wordpress

1k views Asked by At

i want to edit the content in the ob_start but not working

my code:

<?php ob_start(); ?> 
echo "Bird";
<?php apply_filters('filter_name',ob_get_clean()); ?>

custom:

<?php
add_filter('filter_name','my_hook');`
function my_hook(){
echo "Duck";
}

expect results : Duck

1

There are 1 answers

0
Olivier On
  1. Start buffer
  2. Add stuff to buffer
  3. Return & clean buffer contents

Example:

function some_function() {
  ob_start();
  include( plugin_dir_path( __FILE__ ) . 'someOutput.php');
  include( plugin_dir_path( __FILE__ ) . 'moreOutput.php');
  include( plugin_dir_path( __FILE__ ) . 'finalOutput.php');
  return ob_get_clean();
}