I am sure there is a logical answer to this but I don't see it explained anywhere. Bear with the newb here.
What are the differences between action hooks and filter hooks?
Thanks
I am sure there is a logical answer to this but I don't see it explained anywhere. Bear with the newb here.
What are the differences between action hooks and filter hooks?
Thanks
an action hook is like a coat hook. it is a place where you can hang any kind of coat.
a filter hook is more like a ball pit. with the filter you can change the color/type of the ball in the pit? yeah, i still haven't perfected my filter metaphor. but filters let you pass in different variables.
If you stick with the popular "car" metaphors used in, well, pretty much everything...
Imagine your website is a parking lot, with the different elements of your site being cars. Action hooks add or remove cars, while filters are used to somehow change an existing car (say, from blue to red).
Action hooks add or remove elements, filter hooks change how elements are presented (I say "presented", because filters don't change the actual contents in the database, they just change the contents into a different form for presentation).
In Thematic, you would use an action hook to add a featured posts section below the header:
function kwight_add_featured_posts() { ?>
<div id="featured">
<!-- featured posts code -->
</div><!-- end featured -->
<?php }
add_action('thematic_belowheader','kwight_add_featured_posts');
However, you would use a filter hook to change the existing "read more" text:
function kwight_change_more_text($content) {
$content = 'Continue reading >';
return $content;
}
add_filter('more_text', 'kwight_change_more_text');
I find filter hooks a little more difficult to wrap your head around, as they can do so much and be used in so many different ways; they can not only change elements, but add to, replace and completely remove them.
This link might also help:
Um... something like that.
Kwight that's a good description. Sorry HTV I have no clue what a ball pit is, must be Canadian :)
well i did warn you that i hadn't worked out my metaphor yet. but seriously, no ball pits in canada?
http://www.youtube.com/watch?v=CDNCfMmC0SQ
that is a shame. or a dommage depending on which part of canada you are from.
i do like the parking lot metaphor. i will probably steal it the next time someone asks this question...
Oh so that's a ball pit! I never knew what they were called. but I remember the Simpsons episode "the children look unhappy, add more balls" For some reason I thought YOU were Canadian, I have no idea why. I'm in San Francisco. merci quand même.
yup! ball pit is an uber-creative name for a pit, full of balls. nope, american all the way here, but located all over... (2 years in france explains the attempts at français). which is better than my Polish. just got back from 3 months in Poland and all i can really say is pierogies please.
Funny, I didn't get the "ball pit" reference either (and I am Canadian). I guess it's just one of those things that exists, but we've never really had to call it by name (like a tine - I'll let everyone look it up :)
If I'm ever smart enough to come up with a really good theme, I'll name it BallPitPierogiesTine in honor of y'all
ok, so i think its clear. ball pit = bad metaphor.
I think no knowledge of ball pits = bad childhood :\
@siguy for the win! i concur! i've been meaning to work up some graphics for a parking lot metaphor, but i'm always swamped.
This topic has been closed to new replies.