Title: referencing theme directory from custom function
Last modified: August 19, 2016

---

# referencing theme directory from custom function

 *  [zoion](https://wordpress.org/support/users/zoion/)
 * (@zoion)
 * [18 years, 1 month ago](https://wordpress.org/support/topic/referencing-theme-directory-from-custom-function/)
 * I’m trying to write a function to include in my theme that opens a text file 
   for input. Is there a WordPress variable I can use instead of the absolute file
   path?
 * Instead of: `$textfile = "blah/blah/blah/textfile.txt"`

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

 *  [garbonzo](https://wordpress.org/support/users/garbonzo/)
 * (@garbonzo)
 * [18 years, 1 month ago](https://wordpress.org/support/topic/referencing-theme-directory-from-custom-function/#post-745932)
 * Take a look at [get_bloginfo](http://codex.wordpress.org/Template_Tags/get_bloginfo)
 *  Thread Starter [zoion](https://wordpress.org/support/users/zoion/)
 * (@zoion)
 * [18 years, 1 month ago](https://wordpress.org/support/topic/referencing-theme-directory-from-custom-function/#post-746037)
 * I can’t use an absolute path, I need a local path.
 *  Moderator [Samuel Wood (Otto)](https://wordpress.org/support/users/otto42/)
 * (@otto42)
 * WordPress.org Admin
 * [18 years, 1 month ago](https://wordpress.org/support/topic/referencing-theme-directory-from-custom-function/#post-746040)
 * Use the get_template_directory() function.
 * `$path_to_theme_directory = get_template_directory();`
 * Also, that documentation on get_bloginfo was wrong, I’ve corrected it. It will
   also work for this case.
 *  Thread Starter [zoion](https://wordpress.org/support/users/zoion/)
 * (@zoion)
 * [18 years, 1 month ago](https://wordpress.org/support/topic/referencing-theme-directory-from-custom-function/#post-746044)
 * This is my setup.
 * In theme:
    `<?php include(TEMPLATEPATH . '/includes/random.inc.php'); ?> <?php
   if (function_exists('randomWit')) echo randomWit(); ?>
 * In random.inc.php:
    `<? function randomWit ( $textfile = "long local path to/
   random.txt" ){; if ($quotes = @file("$textfile")) { $quote = rand(0, sizeof($
   quotes)-1); echo $quotes[$quote]; echo (""); }}; ?>
 *  Moderator [Samuel Wood (Otto)](https://wordpress.org/support/users/otto42/)
 * (@otto42)
 * WordPress.org Admin
 * [18 years, 1 month ago](https://wordpress.org/support/topic/referencing-theme-directory-from-custom-function/#post-746045)
 * … Okay, but I fail to see how that’s relevant.
 * What, exactly, are you asking? Could you rephrase the question, perhaps in a 
   way that will let us know what you’re talking about?
 *  Thread Starter [zoion](https://wordpress.org/support/users/zoion/)
 * (@zoion)
 * [18 years, 1 month ago](https://wordpress.org/support/topic/referencing-theme-directory-from-custom-function/#post-746165)
 * In random.inc.php I’d like to not hardcode the local path to random.txt, but 
   I don’t quite know how.

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

The topic ‘referencing theme directory from custom function’ is closed to new replies.

## Tags

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

 * 6 replies
 * 3 participants
 * Last reply from: [zoion](https://wordpress.org/support/users/zoion/)
 * Last activity: [18 years, 1 month ago](https://wordpress.org/support/topic/referencing-theme-directory-from-custom-function/#post-746165)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
