Title: how can I include some custom variable from functions.php?
Last modified: August 31, 2016

---

# how can I include some custom variable from functions.php?

 *  Resolved [piopruua](https://wordpress.org/support/users/piopruua/)
 * (@piopruua)
 * [10 years, 4 months ago](https://wordpress.org/support/topic/how-can-i-include-some-custom-variable-from-functionsphp/)
 * For example, if I add this code to functions.php:
 * `$mysite_address_url="http://my-site.com";`
 * And then add this to one of my .php template files(like index.php or header.php):
 * `<?php echo($mysite_address_url); ?>`
 * It won’t work. Why is this happens and how can I achieve this with wordpress 
   please?

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

 *  [Andrew Nevins](https://wordpress.org/support/users/anevins/)
 * (@anevins)
 * WCLDN 2018 Contributor | Volunteer support
 * [10 years, 4 months ago](https://wordpress.org/support/topic/how-can-i-include-some-custom-variable-from-functionsphp/#post-7049426)
 * See [https://gist.github.com/aahan/7444046](https://gist.github.com/aahan/7444046)
 *  Thread Starter [piopruua](https://wordpress.org/support/users/piopruua/)
 * (@piopruua)
 * [10 years, 4 months ago](https://wordpress.org/support/topic/how-can-i-include-some-custom-variable-from-functionsphp/#post-7049428)
 * So, with my example, I should do this, right(?):
 *     ```
       function my_global_vars() {
   
           global $myglobvar;
           $myglobvar= array(
   
               'mysite_address_url'  => get_query_var('http://my-site.com'),
   
           );
   
       }
       add_action( 'parse_query', 'my_global_vars' );
       ```
   
 * And what then?
 *  [Andrew Nevins](https://wordpress.org/support/users/anevins/)
 * (@anevins)
 * WCLDN 2018 Contributor | Volunteer support
 * [10 years, 4 months ago](https://wordpress.org/support/topic/how-can-i-include-some-custom-variable-from-functionsphp/#post-7049430)
 * Then it’s available in your template under:
 *     ```
       $GLOBALS['mysite_address_url']
       ```
   
 *  Thread Starter [piopruua](https://wordpress.org/support/users/piopruua/)
 * (@piopruua)
 * [10 years, 4 months ago](https://wordpress.org/support/topic/how-can-i-include-some-custom-variable-from-functionsphp/#post-7049431)
 * Like this(?):
    <?php echo($GLOBALS[‘mysite_address_url’]); ?>
 * And another question please, is it safe to use this globals?
 * And thank you for helping me!
 *  [Andrew Nevins](https://wordpress.org/support/users/anevins/)
 * (@anevins)
 * WCLDN 2018 Contributor | Volunteer support
 * [10 years, 4 months ago](https://wordpress.org/support/topic/how-can-i-include-some-custom-variable-from-functionsphp/#post-7049432)
 * Yes try that
 *  Thread Starter [piopruua](https://wordpress.org/support/users/piopruua/)
 * (@piopruua)
 * [10 years, 4 months ago](https://wordpress.org/support/topic/how-can-i-include-some-custom-variable-from-functionsphp/#post-7049434)
 * I just tried it and it is not working.
    I tried the above and did this in my 
   index.php: `<a href="<?php echo($GLOBALS['mysite_address_url']); ?>">TEST</a>`
 * and I got this instead:
 *     ```
       <a href="<br />
       <b>Notice</b>:  Undefined index: mysite_address_url in <b>/home/www/blablabla/wp-content/themes/blabla/index.php</b> on line <b>blabla</b><br />
       ">TEST</a>
       ```
   
 *  [Andrew Nevins](https://wordpress.org/support/users/anevins/)
 * (@anevins)
 * WCLDN 2018 Contributor | Volunteer support
 * [10 years, 4 months ago](https://wordpress.org/support/topic/how-can-i-include-some-custom-variable-from-functionsphp/#post-7049436)
 * Oh sorry, it’s meant to be this:
 *     ```
       <?php echo($GLOBALS['myglobvar']['mysite_address_url']); ?>
       ```
   
 *  Thread Starter [piopruua](https://wordpress.org/support/users/piopruua/)
 * (@piopruua)
 * [10 years, 4 months ago](https://wordpress.org/support/topic/how-can-i-include-some-custom-variable-from-functionsphp/#post-7049439)
 * Thanks, Andrew! It worked! But can you please tell me how safe is this to use
   global variables or there’s nothing to worry about it?
 *  [Andrew Nevins](https://wordpress.org/support/users/anevins/)
 * (@anevins)
 * WCLDN 2018 Contributor | Volunteer support
 * [10 years, 4 months ago](https://wordpress.org/support/topic/how-can-i-include-some-custom-variable-from-functionsphp/#post-7049445)
 * Have you read something that says it’s insecure? I couldn’t find anything about
   global variables being insecure, but I don’t know
 *  Thread Starter [piopruua](https://wordpress.org/support/users/piopruua/)
 * (@piopruua)
 * [10 years, 4 months ago](https://wordpress.org/support/topic/how-can-i-include-some-custom-variable-from-functionsphp/#post-7049450)
 * Thanks once again, Andrew!

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

The topic ‘how can I include some custom variable from functions.php?’ is closed
to new replies.

## Tags

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

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 10 replies
 * 2 participants
 * Last reply from: [piopruua](https://wordpress.org/support/users/piopruua/)
 * Last activity: [10 years, 4 months ago](https://wordpress.org/support/topic/how-can-i-include-some-custom-variable-from-functionsphp/#post-7049450)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
