Advertisement
georgi_yankov

[WordPress] add_filter() in a loop - version 3

Aug 22nd, 2014
272
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.44 KB | None | 0 0
  1. add_filter('the_content', 'callback_func');
  2.  
  3. function callback_func($content) {
  4.     $map = array(
  5.         1 => array(
  6.             'foo' => 'black',
  7.             'bar' => 'white'
  8.         ),
  9.         2 => array(
  10.             'foo' => 'red',
  11.             'bar' => 'blue'
  12.         )
  13.     );
  14.    
  15.     for ($i = 1; $i <= 2; $i++) {
  16.         $content = str_ireplace($map[$i]['foo'], $map[$i]['bar'], $content);
  17.     }
  18.    
  19.     return $content;
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement