[wp-hackers] add_filter before or after function?

Jeremy Visser jeremy.visser at gmail.com
Thu Aug 30 01:54:47 GMT 2007


DD32 wrote:
> add_filter('query_vars', 'test_queryvars' );
> function test_queryvars( $qvars ){
>     $qvars[] = 'artist_slug';
>     $qvars[] = 'artist_page';
>     return $qvars;
> }

I notice you add the add_filter() _before_ you declare the actual
function. Others do that too, while other add the add_filter() (or
add_action()) _after_ the function.

Which is best?

I tend to put it after the function because, well, if you put it before,
aren't you referencing a non-existant function? What if add_filter() one
day adds a check to see if the function_exists()? If you do add_filter()
first, then won't it break?

I'm not knowledgeable enough with PHP to really know which is right.


More information about the wp-hackers mailing list