WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Does wordpress allow me to add a php file to the root directory to execute custom scripts?

I need functionality similar to functions.php that you put into themes.

Are there any work arounds that don't involve modifying the config.php file?

share|improve this question
up vote 1 down vote accepted

Does wordpress allow me to add a php file to the root directory to execute custom scripts?

WordPress can't prevent you from adding PHP files to the root directory, but there is no builtin functionality to load those files. You can load them yourself but if you are not careful they will load outside of WordPress context, which is a painful way to work.

What you want, almost certainly, is a plugin or a MU-Plugin. MU-Plugins work similar to what you are asking, if I understand you, but instead of placing your file in the site root you would place it in wp-content/mu-plugins/. It will be loaded automatically for all sites in the network and cannot be disabled except by deletion from the server.

share|improve this answer
Will the mu-plugins work before WordPress is installed? – Ben May 3 '14 at 1:37
No. Are you trying to run an install script? – s_ha_dum May 3 '14 at 1:58
I created a mu-plugin folder inside wp-content and placed a php file inside (NOT IN A SUB FOLDER) and am running it. It only runs after word press installed which is fine. I am writing configuration settings for git that relate to database information. – Ben May 3 '14 at 2:21

I can't think of any valid reason why you'd want to do what you're proposing to do. Wordpress has many hooks that you can use to run code at virtually any stage. For example


some_function() {
do_stuff here 

Would essentially run everytime wordpress is called (Ie:, page loaded) allowing you to do whatever you want. That code can either be added into your themes function.php file, or even in a standalone plugin.

TLDR, there's really no reason why you'd ever need to run a script from wordpresses root directory.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.