Title: pass variable to a php file
Last modified: August 20, 2016

---

# pass variable to a php file

 *  Resolved [dc_photo](https://wordpress.org/support/users/dc_photo/)
 * (@dc_photo)
 * [14 years ago](https://wordpress.org/support/topic/pass-variable-to-a-php-file/)
 * Guys,
 * I am modifying the toolbox theme.
    I wrote a ‘whatever.php’ file, and put it 
   under:
 * > wp-content/themes/toolbox/php/whatever.php
 * Now, if I just include it in index.php, it works fine. When I try to pass variables
   however like this:
 * > include(‘php/whatever.php?myvar=3’)
 * , it breaks down.
 * I understand (from the php manual) that I need to include the full path for this
   to work. However, attempts like:
 * > include(‘[http://mysite.com/wp-content/themes/toolbox/php/whatever.php?myvar=3&#8217](http://mysite.com/wp-content/themes/toolbox/php/whatever.php?myvar=3&#8217);)
 *  of course fail…
 * What am I doing wrong? Or is it simply not possible to do this – as I think I
   read?!
 * I know I could use global variables, but I don’t really want to.
 * Many thanks
    D.

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

 *  [esmi](https://wordpress.org/support/users/esmi/)
 * (@esmi)
 * [14 years ago](https://wordpress.org/support/topic/pass-variable-to-a-php-file/#post-2721196)
 * Why are you including a template file?
 *  Thread Starter [dc_photo](https://wordpress.org/support/users/dc_photo/)
 * (@dc_photo)
 * [14 years ago](https://wordpress.org/support/topic/pass-variable-to-a-php-file/#post-2721199)
 * Because I need to generate for my page 30 similar html elements which vary depending
   on these variables … but does it really matter?
 *  [esmi](https://wordpress.org/support/users/esmi/)
 * (@esmi)
 * [14 years ago](https://wordpress.org/support/topic/pass-variable-to-a-php-file/#post-2721203)
 * Yes. The more we know about what you are trying to achieve, the better the chance
   that we can come up with a workable solution. For example, why not use a function
   in functions.php instead of whatever.php and pass your variables as function 
   arguments?
 *  Thread Starter [dc_photo](https://wordpress.org/support/users/dc_photo/)
 * (@dc_photo)
 * [14 years ago](https://wordpress.org/support/topic/pass-variable-to-a-php-file/#post-2721204)
 * Ah, ok. So you mean transfer the content of whatever.php into functions.php and
   then simply call it from say index.php whenever I need it? OK, I think I got 
   it.
 * But still just to confirm, what I was trying to do is not possible, is it?
 * Many thanks for your help!
 *  [esmi](https://wordpress.org/support/users/esmi/)
 * (@esmi)
 * [14 years ago](https://wordpress.org/support/topic/pass-variable-to-a-php-file/#post-2721210)
 * > So you mean transfer the content of whatever.php into functions.php and then
   > simply call it from say index.php whenever I need it?
 * Yep. Using a standard PHP `include` in WordPress is always dicey because of the
   way in which the whole templating system works.
 *  Thread Starter [dc_photo](https://wordpress.org/support/users/dc_photo/)
 * (@dc_photo)
 * [14 years ago](https://wordpress.org/support/topic/pass-variable-to-a-php-file/#post-2721218)
 * I just transferred it to functions.php and it works like a charm, many thanks
   again!
 *  [esmi](https://wordpress.org/support/users/esmi/)
 * (@esmi)
 * [14 years ago](https://wordpress.org/support/topic/pass-variable-to-a-php-file/#post-2721222)
 * Glad I could help 🙂

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

The topic ‘pass variable to a php file’ is closed to new replies.

## Tags

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

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 7 replies
 * 2 participants
 * Last reply from: [esmi](https://wordpress.org/support/users/esmi/)
 * Last activity: [14 years ago](https://wordpress.org/support/topic/pass-variable-to-a-php-file/#post-2721222)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
