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?
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It only takes a minute to sign up.
Sign up to join this communityDoes 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.
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
add_action('init','some_function');
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.