Title: Calling WordPress functions from a file.php inside the theme
Last modified: August 22, 2016

---

# Calling WordPress functions from a file.php inside the theme

 *  Resolved [ominem](https://wordpress.org/support/users/ominem/)
 * (@ominem)
 * [11 years, 2 months ago](https://wordpress.org/support/topic/calling-wordpress-functions-from-a-filephp-inside-the-theme/)
 * Hello, I created a file.php inside my theme folder that is called when a user
   clicks on a link on a page that has applied a page-template. Inside that file.
   php I clear some $_SESSION variables and the need to redirect to homepage. The
   problem is that this file doesn’t recognize any of wordpress constants or functions:
   
   1- Notice: Use of undefined constant ABSPATH – assumed ‘ABSPATH’ 2- Fatal error:
   Call to undefined function wp_redirect() What could be the problem? I’m using
   Twenty_Fourteen theme modified. Thanks in advance

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

 *  [bernbe01](https://wordpress.org/support/users/bernbe01/)
 * (@bernbe01)
 * [11 years, 2 months ago](https://wordpress.org/support/topic/calling-wordpress-functions-from-a-filephp-inside-the-theme/#post-5819005)
 * hey!
 * file.php is not part of wordpress, so without including some core wp classes 
   it won’t have access to their vars or functions
 * if you want to integrate it using the wp classes i believe you can add this line
   to the top of your php file (it assumes wordpress is *not* installed in a subdirectory)
 * > `include_once($_SERVER['DOCUMENT_ROOT'].'/wp-load.php' );`
 * another way: is it possible that at the point of link creation (the page before
   file.php gets called) that you could pass the needed vars as $_SESSION or $_GET
   vars you define?
 *  Thread Starter [ominem](https://wordpress.org/support/users/ominem/)
 * (@ominem)
 * [11 years, 2 months ago](https://wordpress.org/support/topic/calling-wordpress-functions-from-a-filephp-inside-the-theme/#post-5819007)
 * it worked perfect, thank you very much.

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

The topic ‘Calling WordPress functions from a file.php inside the theme’ is closed
to new replies.

## Tags

 * [constants](https://wordpress.org/support/topic-tag/constants/)
 * [functions](https://wordpress.org/support/topic-tag/functions/)
 * [redirect](https://wordpress.org/support/topic-tag/redirect/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 2 replies
 * 2 participants
 * Last reply from: [ominem](https://wordpress.org/support/users/ominem/)
 * Last activity: [11 years, 2 months ago](https://wordpress.org/support/topic/calling-wordpress-functions-from-a-filephp-inside-the-theme/#post-5819007)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
