Storing WordPress statements as a function for multiple use?

I find myself using something like this a lot in my sites:

if (is_tree(88) || is_tree(4595) || is_page(2) || is_category(70) ) { 
    ...do something
}

I may use this in several template files which means as my site grows and I need to add new conditions to the statement I have to apply the changes everywhere in my theme.

Read More

Is it possible to store this somewhere (I’m thinking functions.php) and call it in the template files?
That way, when I need to change it, I can do so once and it’s applied everywhere.

Related posts

Leave a Reply

1 comment

  1. Using a function might help. That way, you can add it to the functions.php file and include it across pages and you can add more conditional parameters in one place.

    Something like this:

    function if_condn(){
        return (is_tree(88) || is_tree(4595) || is_page(2) || is_category(70));
    }
    

    And use it like this in other theme files:

    if(if_condn()){
        ...
    }