Title: Adding custom php code
Last modified: August 20, 2016

---

# Adding custom php code

 *  [jeffrydell](https://wordpress.org/support/users/jeffrydell/)
 * (@jeffrydell)
 * [14 years, 4 months ago](https://wordpress.org/support/topic/adding-custom-php-code/)
 * I’m looking for a simple answer to a simply issue – hopefully conforming to WordPress
   Best Practices (if at all possible).
 * I don’t want to WRITE a plugin or a widget. If I need to USE one, that’s fine,
   but I don’t want to get in to new syntax if I can at all possibly avoid doing
   so.
 * My desire is to be able to include my forms and form processing in to pages in
   the simplest way possible, while keeping all my custom code in a separate directory
   on the site. So my WP install and the site home is [http://domain.com/wordpress](http://domain.com/wordpress),
   which means that home is [http://domain.com/wordpress/index.php](http://domain.com/wordpress/index.php).
   I have all my custom stuff in [http://domain.com/wordpress/my-includes](http://domain.com/wordpress/my-includes)
 * I have been using Exec-PHP plugin in the past and it worked fine for this as 
   long as I was including a file in the site root ([http://domain.com/myFile.php](http://domain.com/myFile.php)),
   but now I’m having trouble properly referencing the file (Don’t know how to get
   to it … do I use /my-includes/file.html, ../my-includes/file.html, my-includes/
   file.html … what? It seems that everything I try comes up with a php warning 
   and fatal error that the file is not being found.
 * The one exception is when I use site_url() . /my-includes/file.html
    When I try
   to reference the file in that manner, I get an error that http:// is not allowed.
 * So what IS the right way to do what I want to do? Can I include custom html or
   php without a plugin? Is there a better plugin? Help!
 * Thanks!
 * Jeff

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

 *  [racer x](https://wordpress.org/support/users/racer-x-1/)
 * (@racer-x-1)
 * [14 years, 4 months ago](https://wordpress.org/support/topic/adding-custom-php-code/#post-2407022)
 * > but I don’t want to get in to new syntax if I can at all possibly avoid doing
   > so.
 * There really is no new “syntax” for a plugin. It’s all php and WordPress hooks,
   filters, etc.
 * When including files it is sometimes best to use the full path which is why site_url()./
   my-includes/file.html was able to access the file in question. You wouldn’t put
   a plugin file there anyway. You’d put it in your Plugins folder.
 * Anyway, you don’t really need a plugin that executes php in the content area 
   to process forms. You can simply have the form action go to the file that actually
   processes the form. After processing, you can direct the user back to a regular
   page. (Like a thank you page, etc.)
 * Or create a [custom page template](http://codex.wordpress.org/Pages) file that
   has the php directly in the file itself. Not in the wordpress edit screen.
 * It is not advisable to have php allowed directly in edit screens anyway and that
   plugin has not been updated since 2009. You should only use plugins that are 
   up to date.
 * Lastly, I am not a fan of plugins in general, though, if they are well received
   by the WP community, I try them out. There are MANY that are not only great, 
   but almost silly “not” to use. For i.e. Contact form 7 is so easy to use I almost
   always use it for any site that wants a contact form. Take advantage of what 
   the community has to offer!
 * Best of luck!
 *  Thread Starter [jeffrydell](https://wordpress.org/support/users/jeffrydell/)
 * (@jeffrydell)
 * [14 years, 4 months ago](https://wordpress.org/support/topic/adding-custom-php-code/#post-2407033)
 * > When including files it is sometimes best to use the full path which is why
   > site_url() . /my-includes/file.html was able to access the file in question.
 * I was using php to include my form:
 *     ```
       <?php require(site_url() . '/my-includes/file.html')
       ```
   
 * Never even got to the part where I was going to try to process the results. Besides,
   the above syntax didn’t work because something was whining about the ‘[http://&#8217](http://&#8217);
   being included in the path. My Server? Plugin? WordPress? I dunno.
 * I get what you are saying about ‘old plugins’ and I generally steer clear of 
   them too. This one, however, was always just an easy fix for what I was trying
   to accomplish.
 * So I’m still not clear on what to do with the form. I’d rather keep it in a separate
   file rather than putting it on the page – because certain forms can appear in
   multiple places as a part of different forms. There are a LOT of forms on this
   site!
 * Am I restricted to just copying the HTML from one page to the other or can I 
   somehow include an HTML file within the page?
 * Thanks again!
 *  Thread Starter [jeffrydell](https://wordpress.org/support/users/jeffrydell/)
 * (@jeffrydell)
 * [14 years, 4 months ago](https://wordpress.org/support/topic/adding-custom-php-code/#post-2407058)
 * Muddling by using the Snippets plugin for now. Not sure if that’s the 100% answer,
   but it seems to be working for now.

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

The topic ‘Adding custom php code’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 3 replies
 * 2 participants
 * Last reply from: [jeffrydell](https://wordpress.org/support/users/jeffrydell/)
 * Last activity: [14 years, 4 months ago](https://wordpress.org/support/topic/adding-custom-php-code/#post-2407058)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
