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.

  1. karim morgo says:

    what id i want to continue creating the theme without using FTP access !?

  2. Olamosh says:

    wow! Bravo P Chandra,

    Am a wordpress wrangler but i never knew of this method. To sincere you make my day with this article post.

    This is really a great way to create a new PHP file/template inside a wordpress theme.

    I have always create my php file/template offline and connect through FTP in order to upload it. I never knew of this method.

    Thanks for sharing this wonderful trick with us, it shows our geeky you are towards wordpress development and i will urge you to keep up the good writing.

    BUT PLEASE, AFTER CREATING THE FILE, WILL YOU HAVE TO REMOVE THE “” from header.php ???? (await your response)

    I already bookmark this blog because i see alot of interesting articles on it.

    Have a nice weekend

  3. P. Chandra says:

    Once you have created your file, you do not need the line in the header.php. It has to be removed.

  4. Hardy says:

    Thanks for the tips. It is very useful for the newbies like me..

  5. Just Awesome Tips. But When i am Trying to Upload 50 MB WordPress Theme, Then how i can Upload it without FTP ?

  6. is this really help in exporting the hosting & username detailed?

  7. P. Chandra says:

    This works to create empty files in the themes folder. Fresh install need to be done by FTP or in one click via Softalicious or Fantastico in your cpanel.

  8. I have created isolated php file PHPTest.php and accessed using path similar to above mentioned one. Its working perfectly. However my query still open i.e. when the same code is pasted in template related php file it is not even showing the controls.

  9. Well, this thing does really helps when you are testing different themes. I will try it for sure on my new wordpress blog as I have still not decided which theme to use. Thank You for sharing.

  10. mayur says:

    themes are really important as far as appearance is concerned. i am new to wordpress i am trying out for a theme which is simple in appearance and loads faster

  11. rocky kumar says:

    Thank you for posting your blog. I had not any idea about this but you given smart idea for me. I will definitely follow your tips.

  12. david says:

    I find it diffult to understand, i think i need to read it again

Leave a Reply

Your email address will not be published. Required fields are marked *


Share

Free Tips Newsletter

10,000+ subscribers / More info »

css.php