Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Viper007Bond

By: a guest on May 5th, 2009  |  syntax: PHP  |  size: 1.18 KB  |  views: 957  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
This paste has a previous version, view the difference. Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. // In a theme, plugin, or whatever. This filter controls an <h2> with the text "Title".
  2.  
  3. <div class="foobar">
  4.         <h2><?php echo apply_filters( 'coolprefix_some_random_title', 'Title' ); ?></h2>
  5.  
  6. <?php
  7.         // By default, the content is not shown. We can change this filter to "true" to show it.
  8.         if ( true == apply_filters( 'coolprefix_displaycontent', false ) :
  9. ?>
  10.         <p>Some content.</p>
  11. <?php endif; ?>
  12. </div>
  13.  
  14.  
  15. // In a plugin or the theme's functions.php file.
  16.  
  17. <?php
  18.  
  19. add_filter( 'coolprefix_some_random_title', 'my_title_function' );
  20. add_filter( 'coolprefix_displaycontent', 'my_content_function' );
  21.  
  22. function my_title_function( $title ) {
  23.         // Add something onto the end of the existing title
  24.         $title = $title . ' Is Cool';
  25.  
  26.         // Or ignore any existing data (from other filters or the theme)
  27.         $title = 'New Title';
  28.  
  29.         // This is important as we need to allow other filters to filter what we return
  30.         // And to allow the usage of the filter in PHP (i.e. storing it to a variable)
  31.         return $title;
  32. }
  33.  
  34. // This function doesn't accept any parameters because we don't care what was passed to it (i.e. the existing value)
  35. function my_content_function() {
  36.         return true;
  37. }
  38.  
  39. ?>