Writing our WordPress Theme is relatively simple.
Requirements:
Before we begin, we need to know about the following set of requirements.
- We need to have full knowledge of WordPress setup, which is either on the local host or live hosting. Click here to know more about WordPress.
- A conceptual design, either HTML CSS or PSD that follow throughout the development process.
- Basic knowledge of PHP Programming.
Lets Start:
The first thing we need to know that everything we do in WordPress is inside the wp-content directory. When we open the wp,-content->theme file, we will find some default WordPress themes like twentyfifteen, twentythirteen, etc.

We need to create a new file with any name we prefer.
We will call it a “newtheme.”
A WordPress theme contains at least two files, which are index.php and style.css.
Now go into the newtheme folder and create these two files.
In the style.css, we will insert the following comment, which is used to tell the user about the theme details and Meta information.
1 2 3 4 5 6 7 |
/* Theme Name: NewTheme Description: WordPress First Theme Version: 0.8 */ |
Go to the WordPress Dashboard, click on the Appearance-> Themes. We will find NewTheme in the themes collection.

Now, open index.php in the text editor and write the following code.:
1 2 3 4 5 6 7 8 |
<!DOCTYPE html> <html> <body> <h1>Hello WordPress Theme.</h1> </body> </html> |
Sections:
To develop a standard WordPress Theme, we need to divide our work into sections. It is not necessary to do everything in index.php, but a good programming practice involves standardized. We will divide our Theme into four sections, i.e., header, footer, sidebar, and body. These sections are created into four different files, namely, header.php, footer.php, sidebar.php, and content.php.
Lets do our Theme Header (Header.php) :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1" /> <title> <?php echo get_bloginfo( "name" ); ?> </title> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/ css/bootstrap.min.cssintegrity="sha384-BVYiiSIFeK1dG JRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous" /> <link rel="stylesheet" href="<?php echo get_bloginfo ( 'template_directory' ); ?>/style.css" /> <?php wp_head(); ?> </head> |
1 2 3 |
<title> <?php echo get_bloginfo( "name" ); ?> </title> |
This is embedding HTML code into PHP code.
With some additional changes, it becomes:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1" /> <title> <?php echo get_bloginfo( "name" ); ?> </title> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/ bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va +PmSTsz/K68vbdEjh4u" crossorigin="anonymous" /> <link rel="stylesheet" href="<?php echo get_bloginfo ( 'template_directory' ); ?>/style.css" /> <?php wp_head(); ?> </head> <body> <nav class="navbar navbar-default"> <div class="container"> <div class="navbar-header"> <a class="navbar-brand" href="<?php echo esc_url( home_url() ); ?>"> <h3 class="site-branding"> <?php echo get_bloginfo( "name" ); ?> </h3> </a> </div> <ul class="nav navbar-nav navbar-right"> <li class="active"><a href="#">Home</a></li> <li><a href="#">AboutUs</a></li> <li><a href="#">Testimonials</a></li> <li><a href="#">ContactUs</a></li> </ul> </div> </nav> |
1 2 3 |
<?php echo get_bloginfo( 'template_directory' ); ?> |
The above code is used to get the template directory, CSS,JS etc additional resources can be located.
1 2 3 |
<?php echo esc_url( home_url() ); ?> |
The above code is used to echo the homepage url.

Footer.php:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
<footer class="site-footer"> <div class="container"> <div class="row row-30"> <div class="col-md-4 col-xl-5"> <div class="pr-xl-4"> <h3> <a href="<?php echo esc_url( home_url() ); ?>"> <?php echo get_bloginfo( "name" ); ?> </a> </h3> <p><?php echo get_bloginfo( "description" ); ?></p> <p>© 2019|All Rights Reserved|www.tutorialandexample|</p> </div> </div> <div class="col-md-4"> <h5>Contacts</h5> <dl class="contact-list"> <dt>Address:</dt> <dd>Noida,India</dd> </dl> <dl class="contact-list"> <dt>E-Mail:</dt> <dd><a href="mailto:#">tutorialandexample@gmail.com</a></dd></dl> </div> <div class="col-md-4 col-xl-3"> <h5>Links</h5> <ul class="nav-list"> <li><a href="#">Home</a></li> <li><a href="#">AboutUs</a></li> <li><a href="#">Testimonials</a></li> <li><a href="#">ContactUs</a></li> </ul> </div> </div> </div> </footer> <script src="https://code.jquery.com/jquery-1.12.4.min.js" integrity="sha256-ZosEbRLbNQzLpnKIkEdrPv7lOy9C27hHQ+Xp8a4MxAQ=" crossorigin="anonymous"> </script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7 /js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPn CJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"> </script> </body> </html> |
1 2 3 |
<?php echo get_bloginfo( "description" ); ?> |
The above code is used to place the site description.

sidebar.php: Often sidebars display archive links, recent posts, social media accounts, etc. In our Theme, we’ll create archive links and social media links.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
<div class="sidebar"> <div class="widget"> <h3 class="widget-title">Archives</h3> <div class="widget-content"> <ul> <li><a href="#">January 2019</a></li> <li><a href="#">February 2019</a></li> <li><a href="#">March 2019</a></li> </ul> </div> </div> <div class="widget"> <h3 class="widget-title">Connect with Us</h3> <div class="widget-content"> <ul> <li><a href="#">Facebook</a></li> <li><a href="#">Twitter</a></li> <li><a href="#">LinkedIn</a></li> <li><a href="#">Google</a></li> </ul> </div> </div> </div> |
Integration:
In
index.php file, we will integrate all the sections. We have to clearly put
these sections. Lets see how I have done it.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
<?php get_header(); ?> <div class="container"> <div class="row"> <div class="col-md-9"> <?php get_template_part( 'content', get_post_format() ); ?> </div> <div class="col-md-3"> <?php get_sidebar(); ?> </div> </div> </div> <?php get_footer(); ?> |
- In the above code, we have get_header(), get_sidebar() and get_footer() that all are predefined functions used for embedding sections.
And for the custom section like content.php, we have embedded with the following code:
1 2 3 |
<?php get_template_part( 'content',get_post_format() ); ?> |
Style.css: Lets add some charm with CSS.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
/* Theme Name: NewTheme Description: WordPress First Theme Version: 0.8 */ body{ background-image: linear-gradient (to right, #eea2a2 0%, #bbc1bf 19%, #57c6e1 42%, #b49fda 79%, #7ac5d8 100%); } nav.navbar .navbar-brand .site-branding { margin: 0; } footer.site-footer { background-color: black; color: #fff; padding: 40px 0 20px 0; } footer.site-footer a { color: #fff; } |
The Loop:
The Loop is a functionality through which we can insert content into our theme.
1 2 3 4 5 6 |
<?php if (have_posts() ) : while ( have_posts() ) : the_post(); ?> <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?> <!-- contents of the loop --> <?php endwhile; endif; ?> |
content.php:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
<div class="panel-heading"> <h3 class="panel-title post-title"> <?php if( !is_single() ): ?> <a href="<?php echo esc_url( get_permalink() ); ?>"> <?php the_title(); ?> </a> <?php else: the_title(); endif; ?> </h3> <p class="post-meta"> <?php the_date(); ?> by <a href="#"> <?php the_author(); ?> </a> </p> </div> <div class="panel-body"> <?php if( !is_single() ): the_excerpt(); else: the_content(); endif; ?> </div> </div> |
- In the above code, anything which is inside the Loop will be repeated, till the page done with all of its posts.
Changed the (index.php):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
<?php get_header(); ?> <div class="container"> <div class="row"> <div class="col-md-9 blog-main"> <?php if( have_posts() ): while( have_posts() ): the_post(); get_template_part( 'content', get_post_format() ); endwhile; endif; ?> </div> <div class="col-md-3"> <?php get_sidebar(); ?> </div> </div> </div> <?php get_footer(); ?> |
The Loop inside the index.php file is calling the content.php file every time the page has a new updated post. Inside the content.php file, we have checked if the current post is_single(). This condition is used to hold true if the current page contains only a single post to Loop through. If it is not single, we wanted to link to the post via its title. So we used get_permalink() to get the URL for the particular post. If the page is single, there is no need to link it, and therefore, we have used only the_title() function.
We have displayed the_date() which is used to tell the user when the article/post is published and it’s the_author(). At last, we have used the same concept of is_single() which is used to display the_excerpt() or the_content() of the post.
So, it was easy, with the little charm of CSS, we have got the following result:

We are ending this post, but we need to know there is still a lot to learn about WordPress.- It was a simple example, but a standard theme would be much complex.