Title: calling custom function from non wordpress php file
Last modified: August 18, 2016

---

# calling custom function from non wordpress php file

 *  [alternapop](https://wordpress.org/support/users/alternapop/)
 * (@alternapop)
 * [19 years, 3 months ago](https://wordpress.org/support/topic/calling-custom-function-from-non-wordpress-php-file/)
 * i’m learning php and created my own php file. if i call the main function within
   that php file and load it, it works. such as:
 * `mainfunction('var', 1);`
 * it successfully writes the expected text to the browser window.
    if i remove 
   that main function call from that php file itself and add it to a .html page 
   in the same directory like this:
 *     ```
       <body>
       <?php include("filename.php"); ?>
       <?php mainfunction('var', 1); ?>
       </body>
       ```
   
 * and then load that .html file, nothing happens… no errors, no text is written
   to screen, etc. changing “include” to “require” does nothing different.
 * if i add the comments to the top of my php file to turn it into a wp-plugin and
   activate it, then call the function the same way, it works.
 * what am i missing?
 * thanks!

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

 *  Moderator [Samuel Wood (Otto)](https://wordpress.org/support/users/otto42/)
 * (@otto42)
 * WordPress.org Admin
 * [19 years, 3 months ago](https://wordpress.org/support/topic/calling-custom-function-from-non-wordpress-php-file/#post-531663)
 * What you’re missing is that only *.PHP files go through the PHP processor. So
   putting PHP code into an *.HTML file is rather pointless. You’d have to change
   your server setup to make it process *.HTML files as if they were *.PHP files.
 * Extensions of files matter.
 *  Thread Starter [alternapop](https://wordpress.org/support/users/alternapop/)
 * (@alternapop)
 * [19 years, 3 months ago](https://wordpress.org/support/topic/calling-custom-function-from-non-wordpress-php-file/#post-531665)
 * hmm… ah….
 * if i put this same .php file in my main wp directory or server root directory
   and include it the same way with an absolute path link, then call the function,
   in theory, should that work?
 *  Moderator [Samuel Wood (Otto)](https://wordpress.org/support/users/otto42/)
 * (@otto42)
 * WordPress.org Admin
 * [19 years, 3 months ago](https://wordpress.org/support/topic/calling-custom-function-from-non-wordpress-php-file/#post-531667)
 * Err… What?
 * Includes only work in PHP files. You can’t do includes from HTML files either.
   So, no.
 * PHP code must be inside PHP files and made using server calls to PHP files. You
   can’t make an HTML file with PHP code in it and expect it to work.
 *  Thread Starter [alternapop](https://wordpress.org/support/users/alternapop/)
 * (@alternapop)
 * [19 years, 3 months ago](https://wordpress.org/support/topic/calling-custom-function-from-non-wordpress-php-file/#post-531669)
 * that’s what i meant. copy the php file to my server directory, somewhere. then
   within my wordpress template, where ever i want that code called, put those two
   lines (include and function call)…
 * that should work, right?
 * thanks!!
 *  Thread Starter [alternapop](https://wordpress.org/support/users/alternapop/)
 * (@alternapop)
 * [19 years, 3 months ago](https://wordpress.org/support/topic/calling-custom-function-from-non-wordpress-php-file/#post-532083)
 * still wondering how to do this… thanks

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

The topic ‘calling custom function from non wordpress php file’ is closed to new
replies.

## Tags

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

 * 5 replies
 * 2 participants
 * Last reply from: [alternapop](https://wordpress.org/support/users/alternapop/)
 * Last activity: [19 years, 3 months ago](https://wordpress.org/support/topic/calling-custom-function-from-non-wordpress-php-file/#post-532083)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
