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?


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.

  • 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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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