The other day I was doing some cowboy coding on a site of a friend. Yeah, I know, cowboy coding is
doing_it_wrong(), but sometimes it’s just quick, dirty and easy…
Anyways, my friend hadn’t given me any FTP details and I really needed to add a template file to the child theme. What to do? Impatient as I am, I was not planning to wait until the next day, although it was already way past my bedtime.
My buddy Google quickly showed me where I could find the solution.
The 4 steps to accomplish this are as follows:
- Open the
header.phpfile in the WordPress theme editor;
<?php touch( 'wp-content/themes/name-(child)-theme/template-file-name.php' ); ?>all the way at the top and hit save;
- Open the site in a new browser window, so that the header file will load and execute the code we just pasted there;
- Remove the line you added in Step 2 and save the file again, you will see your new file now in the file list on the right.
Obviously the file that was just added is entirely blank, so you should immediately add your code to it, especially when you’re on a child theme (which you should be on).
It is good to know that you can use this for any text based file, so also for CSS and of course you can also add your file to a sub folder.
Not something you should do every day, but I thought it is a good enough tip to share in case you’re in such a situation one day.
Use at your own risk!