Title: Include external php file
Last modified: February 7, 2018

---

# Include external php file

 *  [geekinside](https://wordpress.org/support/users/geekinside/)
 * (@geekinside)
 * [8 years, 3 months ago](https://wordpress.org/support/topic/include-external-php-file/)
 * Hi,
    I have a custom php file that I would like to add into header.php file. 
   However, I don’t know the safest way to include that file.
 * I tried to include a php file into home.php this way.
    include get_template_directory().‘/
   scripts/custom.php’;
    -  This topic was modified 8 years, 3 months ago by [geekinside](https://wordpress.org/support/users/geekinside/).
    -  This topic was modified 8 years, 3 months ago by [geekinside](https://wordpress.org/support/users/geekinside/).
    -  This topic was modified 8 years, 3 months ago by [geekinside](https://wordpress.org/support/users/geekinside/).

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

 *  Moderator [Steven Stern (sterndata)](https://wordpress.org/support/users/sterndata/)
 * (@sterndata)
 * Volunteer Forum Moderator
 * [8 years, 3 months ago](https://wordpress.org/support/topic/include-external-php-file/#post-9948792)
 * That should work, assuming you have the proper PHP syntax.
 *  [Jacob Peattie](https://wordpress.org/support/users/jakept/)
 * (@jakept)
 * [8 years, 3 months ago](https://wordpress.org/support/topic/include-external-php-file/#post-9951844)
 * A more up-to-date and child-theme-friendly way is to use the [`get_theme_file_path()`](https://developer.wordpress.org/reference/functions/get_theme_file_path/)
   function:
 *     ```
       include get_theme_file_path( 'scripts/custom.php' );
       ```
   

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

The topic ‘Include external php file’ is closed to new replies.

## Tags

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

 * In: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
 * 2 replies
 * 3 participants
 * Last reply from: [Jacob Peattie](https://wordpress.org/support/users/jakept/)
 * Last activity: [8 years, 3 months ago](https://wordpress.org/support/topic/include-external-php-file/#post-9951844)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
