✅ Step-by-Step Guide to Create a WordPress Theme
1. Set Up WordPress Locally
Before building a theme, install WordPress on your local machine:
- Use tools like XAMPP, MAMP, or Local by Flywheel.
- Create a database using phpMyAdmin.
- Extract WordPress files into
htdocs/your-folder-nameand complete installation via browser.
2. Create a Theme Folder
wp-content/themes/
Create a new folder for your theme, e.g.:
/wp-content/themes/mytheme
3. Create Required Files
At minimum, your theme needs:
| File | Purpose |
|---|---|
style.css | Theme information and styling |
index.php | Main template file |
functions.php | Theme features and scripts |
✅ style.css (Required)
/wp-content/themes/mytheme/style.css
/*
Theme Name: My Custom Theme
Theme URI: https://example.com/
Author: Your Name
Author URI: https://example.com/
Description: A custom WordPress theme
Version: 1.0
License: GNU General Public License v2 or later
*/
✅ index.php (Required)
/wp-content/themes/mytheme/index.php
phpCopyEdit<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title><?php bloginfo('name'); ?></title>
<?php wp_head(); ?>
</head>
<body>
<h1><?php bloginfo('name'); ?></h1>
<p><?php bloginfo('description'); ?></p>
<?php
if ( have_posts() ) :
while ( have_posts() ) : the_post();
the_title('<h2>', '</h2>');
the_content();
endwhile;
else :
echo '<p>No content found</p>';
endif;
?>
<?php wp_footer(); ?>
</body>
</html>
4. Add functions.php
/wp-content/themes/mytheme/functions.php
phpCopyEdit<?php
function mytheme_scripts() {
wp_enqueue_style('style', get_stylesheet_uri());
}
add_action('wp_enqueue_scripts', 'mytheme_scripts');
5. Activate the Theme
- Go to WordPress Admin → Appearance → Themes
- Your theme should appear there.
- Click Activate.
6. Create Additional Template Files (Optional)
To extend your theme:
| File | Purpose |
|---|---|
header.php | Site header (get_header()) |
footer.php | Site footer (get_footer()) |
sidebar.php | Sidebar (get_sidebar()) |
page.php | Page template |
single.php | Single post template |
archive.php | Archive pages |
404.php | Error page |
Example: header.php
phpCopyEdit<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title><?php bloginfo('name'); ?></title>
<?php wp_head(); ?>
</head>
<body>
<header>
<h1><?php bloginfo('name'); ?></h1>
<nav><?php wp_nav_menu(['theme_location' => 'main-menu']); ?></nav>
</header>
Then in index.php, replace the top with:
phpCopyEdit<?php get_header(); ?>
7. Add WordPress Features (Menus, Widgets, etc.)
In functions.php:
phpCopyEdit// Register menu
register_nav_menus(array(
'main-menu' => 'Main Menu',
));
// Enable featured images
add_theme_support('post-thumbnails');
8. Add Screenshot
Create a screenshot of your theme layout and save it as:
scssCopyEditscreenshot.png (1200x900px recommended)
Place it in your theme root. It will show in Appearance → Themes.
✅ Bonus Tips
- Use template hierarchy properly.
- Follow WordPress Coding Standards.
- Use tools like Theme Check plugin to validate.
- Make it responsive with CSS/media queries.
- Use
get_template_part()to modularize code.