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.
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.
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:
And use it like this in other theme files: