How to Create New Files in the WordPress Theme Editor [Explained]

Posted by





Knowing how to create new files within your WordPress theme editor is very important especially for web developers & designers.

Creating files is very crucial mostly for those who may like to change or add new things to their WordPress theme.

Many WordPress users don’t know this trick am about to share with you. If you wish to have access over every single code in your theme, you need to have knowledge of creating new files.

Download Now


Today I will show you how you can create new files in your WordPress theme editor (for free!).

Latest update: Now anyone can create new files in their theme editor (whether you’re a web developer or not) directly from your WordPress dashboard.


Even if you don’t have access to your FTP account, all you need to do is to add few lines of code where necessary.

This method can be used to add share buttons to WordPress without plugin by following this guide.

Now let’s get to the editing part…

Getting started

Log in to your WordPress dashboard, then go to Appearance > Theme Editor > functions.php.

WordPress do not allow its users to create new file directly from their theme editor. They expect that if you wish to do so, you have to login to your FTP account and manually create new files over there.


However some WordPress users cannot access their FTP account due to some reasons. But we have found an alternative method and this is just adding a piece of code to your functions.php file.

Also read:   How to Buy Domain & Hosting Account in Website Hosting [Start Here]

This code will now create new file to your theme editor and place it to your desired location.

Now let’s create new files in the WordPress theme editor

While there are other ways to create new files in your theme editor, in this guide I will be teaching with the PHP’s touch() function which has been tested in different WordPress versions and it worked perfectly.

WordPress recommends that their users can use the PHP’s touch() function in WordPress FileSystem API.

Go to your theme editor; select and open “function.php” of your active theme and add the piece of code below.

I will advise you to scroll down to the last line of code in function.php to avoid altering already existing code end/closing tags.

add_action('after_setup_theme', function() {
	$file = get_stylesheet_directory() . '/my-new-file.php';
	touch($file);
});

After adding this code, click on “Update file” to save changes you’ve made in functions.php. After a successful update, reloading the page will activate the code and your new file will be automatically created in your theme editor.

If you like after your new file has been successfully created, you can comment the code out. But if you’re not good at editing codes, just leave it as it cannot create multiple files with the same name upon updating your functions.php in the future.

Code Explanation – Create New Files in WordPress

get_stylesheet_directory() – This refers to the current active child theme’s root directory. For example “wp-content/themes/jonakyblog/my-new-file.php”.

/my-new-file.php – This is the path to the new file that you’re creating. You can rename the file that you’re creating by modifying this part of code.

Also read:   How to Design Sticky Back-To-Top Button in WordPress without Plugin

For example if you intend to create a new file by name “share-buttons-template.php”, all you need to do is to replace /my-new-file.php with /share-buttons-template.php.

Just know that you can always change the name of the file that you want to create in order to suit your purpose for creating it.

Are you upset on how this article can be useful to you?

Read my guide on How to add share buttons to WordPress without plugin ☑

For more clarification on how to implement this guide, view the image below

Create New Files in the WordPress Theme Editor

Conclusion

That’s how you can create new files in your theme editor without accessing your FTP account.

If you were successful in following these steps, please drop a comment so that we can know if you encountered any problem. Your comment will also help us to regularly update this article.

Have in mind that even if your hosting service does not give you access to FTP panel, with this guide you can satisfactorily create new files.

If you find this guide helpful, share it with your friends. Thanks.

Here are other posts you should read: 

  1. Most Favorite Books by Topic and Category
  2. How to Download YouTube Videos in All Devices
  3. Inspirational Mathematical Differences


2 comments

  1. Hello! Do you use Twitter? I’d like to follow you if that would be okay.
    I’m definitely enjoying your blog and look forward to new posts.