DEV Community

Cover image for Step-by-Step Guide to WordPress Theme Development for Beginner
Bryan Oginga
Bryan Oginga

Posted on

Step-by-Step Guide to WordPress Theme Development for Beginner

Ever found yourself building a WordPress site and you find yourself tied on the limited functionalities and features available in the prebuilt themes and page builders? well, that was me a few years ago,untill I decided to explore the vast realm of WordPress theme development.
Creating your own theme can be a rewarding experience that allows you to fully customize the look and have full grain control of your website. This step-by-step guide will walk you through the basics of developing a WordPress theme from scratch.

Prerequisites

I would also like to mention that to fully maximize the endless flexibility of custom theme development you need to have experience in HTML, CSS, Javascript and PHP. A solid grasp of these technologies is non-negotiable for aspiring WordPress developers, providing the toolkit needed to customize and enhance WordPress sites effectively. With that said, get into it.

Step 1: Setup Your Development Environment

Before you start coding, you need to set up your development environment, where you play around with your code before you push it for production. Luckily for developers, there are a number open-source tools like XAMMP,MAMP,but the one that I recommend is Local because of its user friendliness, ease of installation and robust features.

Set Up a Code Editor:
Choose a code editor like Visual Studio Code, Sublime Text, or Atom and setup the necessary extensions to increase your development productivity. Go ahead and launch the local and create a new project.

Image description

Go ahead and create new project, you can give it any name you want, once that is done, go ahead setup WordPress by proving a username, password and a valid email address

Image description

Once that is setup, go ahead and click “open site” to view your WordPress database and username
You should be able to login to login to your WordPress admin if everything was installed correctly

Understand the WordPress File Structure:
Once you have your development environment and text editor geared up, it’s now time to familiarize yourself with the core WordPress files and directory structure, and template hierarchy especially the wp-content/themes directory where your theme will reside. To do so, navigate to your project folder and open the wp-content folder using visual studio code

Step 2: Create a New Theme Directory
Navigate to wp-content/themes in your WordPress installation and create a new folder to house your theme.

Add Basic Theme Files:

Image description
A theme can have hundreds of files and directories, but a minimum, your theme needs three files:
index.php: The main template file.
style.css: The main stylesheet.
functions.php: The theme functions file used for adding custom functionalities
screenshot.png : A display image for the theme

Step 3: Set Up style.css
Add Theme Information:
Open style.css and add the theme header information at the top. This is necessary for WordPress to recognize your theme.

/*
Theme Name: My Theme
Theme URI: http://example.com/mytheme
Author: Your Name
Author URI: http://example.com
Description: A brief description of your theme.
Version: 1.0
License: GNU General Public License v2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
Tags: custom-theme, responsive, clean
Text Domain: mytheme
*/

Step 4 : The fourth step is create the theme structure
By default, this is the main template file that will display your theme's content to the end user
<!DOCTYPE html>
<html <?php language_attributes(); ?>>
<head>
<meta charset="<?php bloginfo( 'charset' ); ?>">
<title><?php wp_title(); ?></title>
<link rel="stylesheet" href="<?php bloginfo('stylesheet_url'); ?>">
<?php wp_head(); ?>
</head>
<body <?php body_class(); ?>>
<header>
<h1><?php bloginfo('name'); ?></h1>
<p><?php bloginfo('description'); ?></p>
</header>
<main>
<?php
if ( have_posts() ) :
while ( have_posts() ) : the_post();
the_title('<h2>', '</h2>');
the_content();
endwhile;
else :
echo '<p>No content found</p>';
endif;
?>
</main>
<?php wp_footer(); ?>
</body>
</html>

Step 5 : Add functions.php file
The functions.php file is to add theme support for features like menus, post thumbnails, custom post types and allows for more fine grain control of the themes functionality.

`<?php
function mytheme_setup() {
// Add theme support for document title tag
add_theme_support( 'title-tag' );

// Add theme support for post thumbnails
add_theme_support( 'post-thumbnails' );

// Register a primary menu location
register_nav_menus( array(
    'primary' => __( 'Primary Menu', 'mytheme' ),
) );
Enter fullscreen mode Exit fullscreen mode

}
add_action( 'after_setup_theme', 'mytheme_setup' );`

Step 6: Create Additional Template Files
For purposes of clean and readable code ,always split your index.php into header.php and footer.php for better organization.

<!DOCTYPE html>
<html <?php language_attributes(); ?>>
<head>
    <meta charset="<?php bloginfo( 'charset' ); ?>">
    <title><?php wp_title(); ?></title>
    <link rel="stylesheet" href="<?php bloginfo('stylesheet_url'); ?>">
    <?php wp_head(); ?>
</head>
<body <?php body_class(); ?>>
    <header>
        <h1><?php bloginfo('name'); ?></h1>
        <p><?php bloginfo('description'); ?></p>
    </header>
    <main>
        <?php
        if ( have_posts() ) :
            while ( have_posts() ) : the_post();
                the_title('<h2>', '</h2>');
                the_content();
            endwhile;
        else :
            echo '<p>No content found</p>';
        endif;
        ?>
    </main>
    <?php wp_footer(); ?>
</body>
</html>

Enter fullscreen mode Exit fullscreen mode

Step : Prepare for Distribution
Create a Screenshot:

Take a screenshot of your theme and save it as screenshot.png in your theme folder.
Add a README File:

Include a README.txt file with instructions and information about your theme.
Zip Your Theme:

Compress your theme folder into a .zip file for distribution.
Congratulations! You've created your first WordPress theme. Continue exploring and adding features to make your theme unique and fully functional. Happy coding!

Top comments (1)

Collapse
 
nparekh1979 profile image
nparekh1979

I am learning to build wordpress themes from youtube. Can I ask you a question as I am stuck in the beginning of a very long playlist?