WordPress covers about 26% of the website till launched now and it seems that you are the WordPress theme developer, we came to know that, since you are searching about creating new WordPress theme and accidentally landed here. Well, you are in luck with it. We will describe about creating new WordPress theme with the minimal requirement of files to built it.
While developing theme for WordPress, it has almost many files associated with if, if you look towards any of the theme code existing in the WordPress theme repository. But, are all of them required? No, all of those files are not required to build the WordPress theme. So, here we will be pointing out the minimum required files for creating the WordPress theme.
Well, for creating a new WordPress theme, you require some of the files to be present in the file system inside the themes directory of the WordPress install, ie, inside the /wp-content/themes/ folder. Those main files are mainly style.css and index.php, which again needs to be inside the folder too, ie, inside the newly created folder to build the WordPress theme. If any of them is absent, then, the created WordPress theme does not work at all. Hence, here we will provide you the basic and the minimal codes required to build a new WordPress theme from scratch. They are given below:
Create a file named as style.css
WordPress detects the available theme only if there is the presence of this file, not only that, it also requires the proper documentation to detect that it is the WordPress theme or not. The required documentation to be present in this file is given as:
* Theme Name: Creative Blog
* Theme URI: https://napitwptech.com/themes/creative-blog/
* Author: Bishal Napit
* Author URI: https://napitwptech.com/themes/
* Description: A very simple WordPress theme.
* Version: 1.0
The above documentation is the minimal required and recommended code to be present in the style.css file of your built WordPress theme. The description for the above code is as below:
- Theme Name: Name to be given to the theme to be created
- Theme URI: The url of the theme, ie, the link must contain the information about the theme if it is provided
- Author: The name of the theme author
- Author URI: The link to the theme author, if it is present, then, the link should point to the project work done or should be your personal site
- Description: The description of the theme, ie, what the theme is about
- Version: The version number of the theme
Create a file named as index.php
The next important file to build new WordPress theme is index.php. Without this file in your theme, style.css file is of no use. So, both of them must be present. The required codes in index.php file to display the content of posts as well as sidebar areas is as below:
if (have_posts()) :
while (have_posts()) : the_post();
<h2><a href=<?php echo the_permalink(); ?>><?php the_title(); ?></a></h2>
<em>Published on <?php the_time(); ?> by <?php the_author(); ?></em>
<?php the_content(); ?>
<?php comments_template(); ?>
<h2>No Posts Found</h2>
<p>Sorry, there are no posts yet.</p>
The above image shows the newly created WordPress theme in the WordPress theme directory present in your WordPress install, after applying the provided above code in your theme’s file.
Similarly, the above image shows the output of the newly created WordPress theme, as described above. Here, you can see that the header information, post content, sidebar content as well as footer areas is displayed properly.
Hope, now, after you have read the above tutorial and follow up, you know the basic and the required minimal codes for creating the new WordPress theme from scratch and now can develop it being more confident.