Title: loading a custom PHP file
Last modified: April 3, 2017

---

# loading a custom PHP file

 *  [farhadk100](https://wordpress.org/support/users/farhadk100/)
 * (@farhadk100)
 * [9 years, 2 months ago](https://wordpress.org/support/topic/loading-a-custom-php-file/)
 * Hi.
    So, I’ll get straight to this. I have a wordpress website with a custom 
   theme and everything. Now I need to load a custom PHP file like mywebsite.com/
   myfile in it. now here is the issue: I’m using %postname% format for my posts.
   I’ve been using it for more than a year, and using this, when I wanna load myfile,
   it returns a 404 error. But if I use default permalink option, it loads myfile
   perfectly. So my question is, how can I have %postname% permalink format and 
   still be able to load my non-wordpress files? Thank u in advance for your answers.

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

 *  Moderator [Steven Stern (sterndata)](https://wordpress.org/support/users/sterndata/)
 * (@sterndata)
 * Volunteer Forum Moderator
 * [9 years, 2 months ago](https://wordpress.org/support/topic/loading-a-custom-php-file/#post-8988594)
 * My trick: Put all of your PHP in a shortcode and then drop that shortcode into
   an otherwise empty page.
 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [9 years, 2 months ago](https://wordpress.org/support/topic/loading-a-custom-php-file/#post-8989079)
 * Steve’s “trick” is completely valid, but for the sake of presenting alternatives,
   you could make your code page into a page template file. This mainly means adding
   a comment to the very top right after the initial `<?php` that looks roughly 
   like this: `/* Template Name: My Template */` Place the template file in the 
   folder of your active theme, preferably a child theme.
 * You may want to add calls to get_header() and get_footer(). If you do not, you
   should at least call wp_head().
 * Add a new page based on your custom template. Give it a title in order to generate
   a permalink. Publish the page.
 * If you do go the shortcode route, remember all content must be returned from 
   the shortcode handler, do not echo out anything. If your current code as a lot
   of echo and/or HTML content, use the output buffer to collect all output into
   a variable which can then be returned.

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

The topic ‘loading a custom PHP file’ is closed to new replies.

## Tags

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

 * In: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
 * 2 replies
 * 3 participants
 * Last reply from: [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * Last activity: [9 years, 2 months ago](https://wordpress.org/support/topic/loading-a-custom-php-file/#post-8989079)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
