'How to use ob_start and ob_get_clean in wordpress
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
Solution 1:[1]
- Start buffer
- Add stuff to buffer
- 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();
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Olivier |
