Title: How should I include this PHP file?
Last modified: September 1, 2016

---

# How should I include this PHP file?

 *  [WPOso](https://wordpress.org/support/users/wordpress-oso/)
 * (@wordpress-oso)
 * [9 years, 11 months ago](https://wordpress.org/support/topic/how-should-i-include-this-php-file/)
 * I created a file @ wp-content/plugins/echo-values.php
 * Now I’m trying to figure out how to include that file. Just to test it, I’ve 
   put the following code in the file:
 * $MyCountry = ‘USA’;
    echo $MyCountry;
 * I’ve been told that the plugins folder is the best place to put includes. I also
   read somewhere that any file placed in the plugins folder would “autoload.” But
   when I published the file online, I couldn’t find “USA” in the source code.
 * So I apparently have to manually include the file. But what file should I insert
   the include in? I learned that wp-content/plugins/index.php is off limits.
 * Also, I don’t know how to translate this…
 * require_once(“/wp-content/plugins/echo-values.php”);
 * to WordPress syntax. There are some examples @ [https://codex.wordpress.org/Function_Reference/plugins_url](https://codex.wordpress.org/Function_Reference/plugins_url)
   but they’re very confusing. Can someone show me how to write a line of code including
   wp-content/plugins/echo-values.php?
 * Thank you.

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

 *  Moderator [t-p](https://wordpress.org/support/users/t-p/)
 * (@t-p)
 * [9 years, 11 months ago](https://wordpress.org/support/topic/how-should-i-include-this-php-file/#post-7468338)
 * If understand you, have you tried creating /mu-plugins/ directory and placing
   this echo-values.php inside it?
 * Looks like this: /wp-content/plugins/mu-plugins/echo-values.php
 * [http://codex.wordpress.org/Must_Use_Plugins](http://codex.wordpress.org/Must_Use_Plugins)
 *  Thread Starter [WPOso](https://wordpress.org/support/users/wordpress-oso/)
 * (@wordpress-oso)
 * [9 years, 11 months ago](https://wordpress.org/support/topic/how-should-i-include-this-php-file/#post-7468340)
 * Actually, this turned into two problems, one of which I just solved. As you suggested,
   I created a new folder – mu-plugins – put my file inside it, and it does autoload.
 * However, I still need to know how to write includes.
 * The file inside my mu-plugins folder is fine for creating echo values, but if
   I want to actually display something at the beginning of an article or at the
   bottom of the page, then I need to be able to insert an include in the proper
   location.
 * Also, I’m eventually going to put some database-driven reference tables on some
   of my pages, so I’ll have to include separate files that feature queries and 
   a lot of styling, etc.
 * Anyway, what’s the proper way to write an include?
 *  Moderator [t-p](https://wordpress.org/support/users/t-p/)
 * (@t-p)
 * [9 years, 11 months ago](https://wordpress.org/support/topic/how-should-i-include-this-php-file/#post-7468342)
 * I don’t follow what you are trying to do. Perhaps someone else can chime in.
 *  [semky](https://wordpress.org/support/users/semky/)
 * (@semky)
 * [9 years, 11 months ago](https://wordpress.org/support/topic/how-should-i-include-this-php-file/#post-7468402)
 * There are plugins to include fies with a short code. and plugins to execute php
   in a post. and if your brave custom fields.
 *  Thread Starter [WPOso](https://wordpress.org/support/users/wordpress-oso/)
 * (@wordpress-oso)
 * [9 years, 11 months ago](https://wordpress.org/support/topic/how-should-i-include-this-php-file/#post-7468403)
 * I found a couple custom fields plugins. Can you list any plugins that help you
   include PHP files? Thanks.
 *  [Jason King](https://wordpress.org/support/users/jasoncharlesstuartking/)
 * (@jasoncharlesstuartking)
 * [9 years, 11 months ago](https://wordpress.org/support/topic/how-should-i-include-this-php-file/#post-7468421)
 * You have so many choices; you could:
 * 1) create a simple shortcode that inserts php. That code could go into functions.
   php or in a plugin. See [https://codex.wordpress.org/Shortcode_API](https://codex.wordpress.org/Shortcode_API).
   Gives you want the flexibility to put the code anywhere you like within post 
   content.
 * Or 2) put that code into one of your theme’s files. If you’re not using a child
   theme, please do so! Then that code could go within one or more of the template
   file in the child theme. Not as flexible as using a shortcode, but still a viable
   option.
 * Or 3) put that code into a widget. Which makes sense if you’ll mainly want to
   place it within widgetised areas. [http://www.wpbeginner.com/wp-tutorials/how-to-create-a-custom-wordpress-widget/](http://www.wpbeginner.com/wp-tutorials/how-to-create-a-custom-wordpress-widget/)
 * Or 4) use a plugin such as [https://wordpress.org/plugins/insert-php/](https://wordpress.org/plugins/insert-php/)
   to insert PHP into any post.
 *  Thread Starter [WPOso](https://wordpress.org/support/users/wordpress-oso/)
 * (@wordpress-oso)
 * [9 years, 11 months ago](https://wordpress.org/support/topic/how-should-i-include-this-php-file/#post-7468424)
 * Thanks, I’ll check those out.

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

The topic ‘How should I include this PHP file?’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 7 replies
 * 4 participants
 * Last reply from: [WPOso](https://wordpress.org/support/users/wordpress-oso/)
 * Last activity: [9 years, 11 months ago](https://wordpress.org/support/topic/how-should-i-include-this-php-file/#post-7468424)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
