Hi, please

Once and for all – the difference between Filters and Hooks

Actually, it is much simpler than you might think:

Filters

Replaces or changes an existing function (from the original Wordpress code, from your Template theme or even one declared by you). It can completely replace the function like here:

<?php
function childtheme_postheader() {
	echo 'bacon';
}
add_filter('thematic_postheader','childtheme_postheader');
?>

Or change the function by adding to it, like here:

<?php
function childtheme_posttitle($posttitle) {
	return '<div class="containing">' . $posttitle . '</div>';
}
add_filter('thematic_postheader_posttitle','childtheme_posttitle');
?>

More about Filters

Action Hooks

Hooks are used to stick a new function (not change an existing one) in different places in the page. There are several hooks in Thematic, each of them can be used as an empty placeholder to be used whenever you want to stick more html or php anywhere in your site

Example:

<?php
// First we make our function
function childtheme_welcome_blurb() {
 
// We'll show it only on the HOME page IF it's NOT paged
// (so, not page 2,3,etc.)
if (is_home() & !is_paged()) { ?>
 
<!-- our welcome blurb starts here -->
<div id="welcome-blurb">
<p>Welcome to <?php bloginfo('name'); ?>.</p>
</div>
<!-- our welcome blurb ends here -->
<?php }
 
} // end of our new function childtheme_welcome_blurb
 
// Now we add our new function to our Thematic Action Hook
add_action('thematic_belowheader','childtheme_welcome_blurb');
?>

More about Action Hooks

One Trackback

  1. [...] If for you’re still unclear on this, read my post about Filters / Action hooks [...]

Post a Comment

You must be logged in to post a comment.