Title: Pass global variable to category.php?
Last modified: August 19, 2016

---

# Pass global variable to category.php?

 *  Resolved Anonymous User
 * (@anonymized-5747181)
 * [15 years, 8 months ago](https://wordpress.org/support/topic/pass-global-variable-to-categoryphp/)
 * Hi all,
 * I’m trying to set a global variable in header.php that is tested in single.php
   and category.php.
 * Below is the code I’m using. This works on single pages, but it does _not_ work
   on category pages.
 * What am I missing?
 * this is in my header.php
 *     ```
       if (in_category( array('cat1','cat2','cat3')) || is_category( array('cat1','cat2','cat3')) || is_page('MyPage')) {
       global $subnav;
       $subnav = "foo";
       }
       ```
   
 * this is in both single.php and category.php
 *     ```
       get_header();
       if ($subnav == "foo") {
       include(something);
       }
       ```
   

Viewing 1 replies (of 1 total)

 *  Thread Starter Anonymous User
 * (@anonymized-5747181)
 * [15 years, 8 months ago](https://wordpress.org/support/topic/pass-global-variable-to-categoryphp/#post-1718811)
 * Forget it. I figured out a workaround by moving the conditionals and setting 
   of the global variable into functions.php.
 * It also tripped me up that is_archive() returns TRUE for category pages as well.

Viewing 1 replies (of 1 total)

The topic ‘Pass global variable to category.php?’ is closed to new replies.

## Tags

 * [global variable](https://wordpress.org/support/topic-tag/global-variable/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 1 reply
 * 1 participant
 * Last reply from: Anonymous User
 * Last activity: [15 years, 8 months ago](https://wordpress.org/support/topic/pass-global-variable-to-categoryphp/#post-1718811)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
