Title: Passing PHP Variable Between Template Files
Last modified: August 19, 2016

---

# Passing PHP Variable Between Template Files

 *  [eddiegiese](https://wordpress.org/support/users/eddiegiese/)
 * (@eddiegiese)
 * [16 years, 6 months ago](https://wordpress.org/support/topic/passing-php-variable-between-template-files/)
 * I’m trying to pass a PHP variable ($pageTitle) that I define in the top section
   of each template page (i.e. 404.php) so that I can call up a specific CSS file
   for unique page styling. It works when I hard-code the variable into the header.
   php file, which is checking for the $pageTitle variable, but not when I put it
   in an individual page and try to pass it to the header.php. I’ve done this on
   multiple other sites that don’t use WordPress without a problem. Can WordPress
   not support this basic functionality? Is there an additional way to define this
   in WordPress?

Viewing 4 replies - 1 through 4 (of 4 total)

 *  [esmi](https://wordpress.org/support/users/esmi/)
 * (@esmi)
 * [16 years, 6 months ago](https://wordpress.org/support/topic/passing-php-variable-between-template-files/#post-1296785)
 * WordPress won’t let you `include` variables in the same way that you might do
   on a non-WP site. One way to approach this might to use a custom field on your
   pages and use the value in that field to determine which stylesheet to load.
 * [http://codex.wordpress.org/Using_Custom_Fields](http://codex.wordpress.org/Using_Custom_Fields)
 * Or perhaps you could use [body_class()](http://quirm.net/2009/08/07/changing-headers-with-wordpress-body_class/)
   if you simply want to style certain blocks differently.
 *  [lancemonotone](https://wordpress.org/support/users/lancemonotone/)
 * (@lancemonotone)
 * [16 years ago](https://wordpress.org/support/topic/passing-php-variable-between-template-files/#post-1297061)
 * I don’t know if you can pass variables between theme files but you _can_ define
   a variable in your theme’s functions.php file, then at the top of each template
   file declare it in the global space:
 * functions.php
 *     ```
       $some_var = 'Hello World!';
       ```
   
 * footer.php (for example)
 *     ```
       global $some_var;
   
       echo $some_var;
       ```
   
 *  [este](https://wordpress.org/support/users/este/)
 * (@este)
 * [15 years, 9 months ago](https://wordpress.org/support/topic/passing-php-variable-between-template-files/#post-1297089)
 * Fantastic **lancemonotone** !!!!
 *  [jcskyrocket](https://wordpress.org/support/users/jcskyrocket/)
 * (@jcskyrocket)
 * [15 years, 8 months ago](https://wordpress.org/support/topic/passing-php-variable-between-template-files/#post-1297096)
 * Very handy!

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Passing PHP Variable Between Template Files’ is closed to new replies.

## Tags

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

 * 4 replies
 * 5 participants
 * Last reply from: [jcskyrocket](https://wordpress.org/support/users/jcskyrocket/)
 * Last activity: [15 years, 8 months ago](https://wordpress.org/support/topic/passing-php-variable-between-template-files/#post-1297096)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
