Advertisement
olie480

Wordpress ob_start / output buffering

Jan 14th, 2016
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.69 KB | None | 0 0
  1. <?php
  2.  
  3. /*
  4. ::_di_frontend.php::
  5. // How to replace template variables with PHP variables
  6. function get_replacement_vars(){
  7.            
  8.     return array(
  9.         '{post_id}' => get_the_ID(),
  10.         '{post_title}' => get_the_title()
  11.     );
  12.            
  13. }
  14.  
  15. $replacements = get_replacement_vars();
  16. $output = str_replace(array_keys($replacements),array_values($replacements), $output);
  17. */
  18.  
  19. function buffer_callback($buffer){  
  20.     // manipulate HTML (replace template tags,
  21.     return str_replace("{name}", "Chris", $buffer);
  22. }
  23.  
  24. function ob_init(){
  25.     ob_start('buffer_callback');
  26. }
  27. add_action('template_redirect', 'ob_init', 0);
  28.  
  29. function ob_shutdown(){
  30.     ob_end_flush();
  31. }
  32. add_action('shutdown', 'ob_shutdown', 1000);
  33.  
  34. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement