@@// In a theme, plugin, or whatever. This filter controls an <h2> with the text "Title".
<div class="foobar">
<h2><?php echo apply_filters( 'coolprefix_some_random_title', 'Title' ); ?></h2>
<?php
// By default, the content is not shown. We can change this filter to "true" to show it.
if ( true == apply_filters( 'coolprefix_displaycontent', false ) :
?>
<p>Some content.</p>
<?php endif; ?>
</div>
@@// In a plugin or the theme's functions.php file.
<?php
add_filter( 'coolprefix_some_random_title', 'my_title_function' );
add_filter( 'coolprefix_displaycontent', 'my_content_function' );
function my_title_function( $title ) {
// Add something onto the end of the existing title
$title = $title . ' Is Cool';
// Or ignore any existing data (from other filters or the theme)
$title = 'New Title';
// This is important as we need to allow other filters to filter what we return
// And to allow the usage of the filter in PHP (i.e. storing it to a variable)
return $title;
}
// This function doesn't accept any parameters because we don't care what was passed to it (i.e. the existing value)
function my_content_function() {
return true;
}
?>