If you are working on a live WordPress site, there might come a time when you would need to upload a new theme file. This is common if you are creating new templates for a WordPress Theme.
No FTP Access
But how would you upload it if you do not have access to the site’s FTP. This is common if you are a freelance WordPress go-to-guy and your client doesn’t want to give you access to an FTP account or maybe they just simply don’t know how to set up an FTP account for you.
You may be tempted to just upload a whole new zip file containing all of the theme files. But this is a tacky way to handle it especially if the WordPress Theme contains more than 200 files and is more than 5mb. But you only need to upload one file right?
Go to your WordPress theme editor. http://yoursite.com/wp-admin/theme-editor.php
Edit the header.php file and add the following code at the very top or the first line.
<?php touch('wp-content/themes/practice-theme/new-file.php'); ?>
Make sure to add it outside any <?php tags otherwise it could cause an error since the code is already wrapped in its own PHP tags.
Save the changes made to the header.php file. Open a new tab in your browser then visit the website. The new file will be created.
You can now remove the code from the header.php.
The code above will create a file named new-file.php in the directory of the Theme which is practice-theme. You should change these two names to suit your needs. For example you can change the directory name to twentyten if that is the theme you are working on, or change the file name to style-extra.css if that is what’s needed.
After the New File is created you can go back to the theme editor and find the newly created file. You can now paste the file’s contents. Don’t forget to save.
The code can be used to create any text-based file like HTML, PHP, CSS, etc…
- PHP – new-template.php, new-function.php
- CSS – new-style.css, page-style.css
If you’re uncomfortable with editing theme files, you can always use a plugin to create a new file without needing an ftp access. This one particular plugin mimics an ftp file manager: WordPress WP-Filemanager though it doesn’t seem to work last time I checked.