Did you ever want to create new WordPress theme template PHP files, but needed FTP access to the 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.
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 shortcodes.php in your theme directory called qotstrap.
<?php touch('wp-content/themes/qotstrap/shortcodes.php'); ?>
Here is what it will look like in the theme editor
Save the header.php file and you will find a blank php file created called nav.php.
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.
Get template parts in WordPress
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. If you want to load a theme file like share_buttons.php in single.php which displays the posts, simply use the get_template_part code like this in single.php
<?php get_template_part(' share_buttons '); ?>
I am sure WordPress theme designers will find this tip handy.