Did you ever want to create new WordPress theme template PHP files, but needed FTP access to server every time. We experiment a lot with WordPress theme designs and it was very cumbersome to keep logging in via FTP to create new theme files like loop.php  or nav.php or other php files to make the code easier to edit and understand.

Advertisements

There had to be an easier way…

New WordPress Template Files Without FTP

PHP has an amazing command called ‘touch’ which allows users with rights to create new php files. So when you are logged in, simply go to Appearance > Editor > header.php and add this single line of code.

Lets say you want to create a new file called nav.php in your theme directory called quickpress.

<?php touch('wp-content/themes/quickpress/nav.php'); ?>

Here is what it will look like in the theme editor

new touch template file

Save the header.php file and you will find a blank php file created called nav.php.

new template file

Now you can add whatever code you like to that.

Note: It is very essential that now you remove the line added to the header.php and save the file again.

Super tip – We prefer breaking down long WordPress template codes into smaller PHP files which are easier to edit and call in the template, such that they can do instant changes throughout the site. It is easy to call these theme template files anywhere in the theme template like this

<?php get_template_part(' nav '); ?>

I am sure WordPress theme designers will find this tip handy.

14 Comments