Creating new files in the WordPress theme editor
WordPress theme editor can be used to modify theme files straight from the WordPress admin dashboard.
The editor is located under Appearance -> Editor, or in case of multi-site WordPress installation, Themes -> Editor (in the Network admin dashboard).
It is most useful for adding snippets of code, action hooks and filters to the child theme’s
functions.php file, how ever, if one were to need to create a new file for the child theme, then there is no option for that. Instead you would need to manually create the file via FTP or terminal access.
As a workaround, it’s possible to add code to
functions.php file that will create a new file into your desired location.
my-file.phpin the child theme’s folder.
functions.php file of your currently active child theme.
Then add the following code to the file and click Update file:
After adding this action, reloading any page should trigger the code and create a new file. Once the file is created most of the code will no longer execute, but should still be deleted or commented out for future use.
get_template_directory(), since this would use the parent theme’s folder which would remove any custom created upon a theme update.
It’s also possible to create a file using PHP’s
touch() function, how ever the WordPress FileSystem API should be the safer option since if that succeeds you’ll know the server is properly configured for WordPress to have filesystem access.