Add template file without FTP access

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:

  1. Open the header.php file in the WordPress theme editor;
  2. Paste <?php touch( 'wp-content/themes/name-(child)-theme/template-file-name.php' ); ?> all the way at the top and hit save;
  3. Open the site in a new browser window, so that the header file will load and execute the code we just pasted there;
  4. 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!

2 Comments

    1. Thanks for your comment, Marcy, nice to see you here!

      Yeah I was happy to find it, comes in handy every now and then.

      Thanks for the tip on the plugin (added the link to your comment, so people won’t have to search), will check that out.

Comments are closed.