• I’m beginning my foray into writing my own php functions and I’ve basically got it down, but when I try and add the functions into the functions.php file instead of directly into a template, they often don’t work.

    For example, I tried creating this function:

    function cn_parentcat ( ) { if (is_category('8')) { echo ('fubar');} }

    If I add the if statement directly to a template (category.php in my case), a-okay. But it’s a no-go in functions.php.

    Is there some query (or something else) I need to pass before I can perform certain actions like this?

    Thanks!

Viewing 1 replies (of 1 total)
  • Moderator Samuel Wood (Otto)

    (@otto42)

    WordPress.org Admin

    Well, it’s possible that you’re out of variable scope or something for some functions, but that particular example you give should have no issues. is_category will work from within any function.

Viewing 1 replies (of 1 total)
  • The topic ‘Writing functions in functions.php’ is closed to new replies.