Title: persistent variables for a theme
Last modified: August 31, 2016

---

# persistent variables for a theme

 *  [pinkhare](https://wordpress.org/support/users/pinkhare/)
 * (@pinkhare)
 * [10 years, 3 months ago](https://wordpress.org/support/topic/persistent-variables-for-a-theme/)
 * I need persistent variables such as global variables, but using global variables
   in global scope(out of functions) is prohibited in developing theme. So I wonder
   how could I make the value of my variables persistent throughout my theme(from
   the start to the end).
    Actually I’m trying to accumulate(or concatenate) strings
   or array values passed through a parameter in the variable in a function whenever
   the function is called, and then print that string or serialized array values
   at the footer as follows:
 *     ```
       function entire_string( $string ) {
           static $entire_string = '';
           $entire_string = ' '.$string;
       }
   
       entire_string('foo');
       entire_string('bar');
   
       add_action('wp_footer', 'print_entire_string');
       function print_entire_string() {
           global $entire_string;
           print_r($entire_string);  // But it does not work! This returns ' '.
       }
       ```
   
 * I have no idea what the problem is. Please teach me how I can achieve my goal,
   please!
 * (P.S: Using `global $entire_string;` with initialization of the variable(`$entire_string
   = '';`) outside of all functions instead of `static $entire_string = '';` works
   just fine!)

The topic ‘persistent variables for a theme’ is closed to new replies.

## Tags

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

 * 0 replies
 * 1 participant
 * Last reply from: [pinkhare](https://wordpress.org/support/users/pinkhare/)
 * Last activity: [10 years, 3 months ago](https://wordpress.org/support/topic/persistent-variables-for-a-theme/)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
