Title: WordPress use external variable on functions.php
Last modified: August 21, 2016

---

# WordPress use external variable on functions.php

 *  [dudd, médecine blog](https://wordpress.org/support/users/80giga/)
 * (@80giga)
 * [12 years, 2 months ago](https://wordpress.org/support/topic/wordpress-use-external-variable-on-functionsphp/)
 * I have a custom php page outside of wordpress, this page is connecting also to
   a external database, and get resultat form a sql query on a variable
 * i use require(‘../wp-blog-header.php’) and require(‘../wp-load.php’) to integrate
   with wordpress.
 * now i need to use this variable on the functions.php of my wordpress theme.
 * i do on my external page :
 *     ```
       <head>
       <connect to my database>
       <my query>
       <get resulte on $variable>
       <require('../wp-blog-header.php')>
       <require('../wp-load.php')>
       ```
   
 * but when i use $variable on my functions.php it do not work ?

Viewing 1 replies (of 1 total)

 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [12 years, 2 months ago](https://wordpress.org/support/topic/wordpress-use-external-variable-on-functionsphp/#post-4712102)
 * Your variable is out of scope for functions on functions.php. The easiest thing
   to do is declare it global on both the external page and in the function on functions.
   php using it.
 * FYI, what you are doing is generally considered very sloppy coding for the WP
   environment. It’s OK if this is for your own site which you maintain, but virtually
   unusable if you may want others to use your code. Relative references to required
   WP core files is considered unacceptable. For external code to use WP resources
   the page either needs to be a page template or requests need to be sent through
   admin-ajax.php or admin-post.php.
 * It’s also not a good idea to directly edit a theme’s functions.php file, your
   custom code should reside in a child theme or plugin and interface with WP through
   filters and actions. You may very well be doing this, but it’s worth mentioning
   in case you are not.
 * You don’t _have_ to do any of this, it’s your site. But if you think you might
   like to share your efforts with the WP community, or you simply take pride in
   well written code, it’s best to follow community established practices.

Viewing 1 replies (of 1 total)

The topic ‘WordPress use external variable on functions.php’ is closed to new replies.

## Tags

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

 * In: [Hacks](https://wordpress.org/support/forum/plugins-and-hacks/hacks/)
 * 1 reply
 * 2 participants
 * Last reply from: [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * Last activity: [12 years, 2 months ago](https://wordpress.org/support/topic/wordpress-use-external-variable-on-functionsphp/#post-4712102)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
