How to Create a WordPress Theme From Scratch
Build a classic WordPress theme from an empty folder: style.css, index.php, functions.php, header and footer, the loop, templates, menus, widgets, assets and the checks before launch.

A WordPress theme needs only two files to be recognized: style.css with a theme header comment, and index.php containing the loop. A usable classic theme adds functions.php (theme supports, menus, assets), header.php and footer.php with wp_head() and wp_footer(), and templates such as single.php, page.php and archive.php chosen by the template hierarchy.
This tutorial builds a classic PHP theme. Block themes, which use HTML templates and theme.json, are covered in building a block theme; compare the two in classic vs block themes.
Step 1: The folder and style.css
Create wp-content/themes/tle-starter/style.css:
/*
Theme Name: TLE Starter
Description: A lightweight classic theme.
Version: 1.0.0
Requires at least: 6.5
Requires PHP: 8.0
Text Domain: tle-starter
License: GPL-2.0-or-later
*/
Step 2: functions.php
<?php
add_action( 'after_setup_theme', function () {
add_theme_support( 'title-tag' ); // WordPress outputs <title>
add_theme_support( 'post-thumbnails' ); // featured images
add_theme_support( 'html5', array( 'search-form', 'gallery', 'caption', 'style', 'script' ) );
add_theme_support( 'responsive-embeds' );
register_nav_menus( array( 'primary' => __( 'Primary menu', 'tle-starter' ) ) );
load_theme_textdomain( 'tle-starter', get_template_directory() . '/languages' );
} );
add_action( 'wp_enqueue_scripts', function () {
$v = wp_get_theme()->get( 'Version' );
wp_enqueue_style( 'tle-starter', get_stylesheet_uri(), array(), $v );
wp_enqueue_script( 'tle-starter', get_template_directory_uri() . '/assets/main.js', array(), $v, array( 'strategy' => 'defer' ) );
} );
Never hard-code <link> or <script> tags in templates; enqueue them so plugins and caching can manage them (enqueueing assets, add_theme_support).
Step 3: header.php and footer.php
<!doctype html>
<html <?php language_attributes(); ?>>
<head>
<meta charset="<?php bloginfo( 'charset' ); ?>">
<meta name="viewport" content="width=device-width, initial-scale=1">
<?php wp_head(); ?>
</head>
<body <?php body_class(); ?>>
<?php wp_body_open(); ?>
<a class="skip-link" href="#main"><?php esc_html_e( 'Skip to content', 'tle-starter' ); ?></a>
<header class="site-header">
<a href="<?php echo esc_url( home_url( '/' ) ); ?>"><?php bloginfo( 'name' ); ?></a>
<?php wp_nav_menu( array( 'theme_location' => 'primary', 'container' => 'nav' ) ); ?>
</header>
<main id="main">
</main>
<footer class="site-footer">© <?php echo esc_html( gmdate( 'Y' ) ); ?> <?php bloginfo( 'name' ); ?></footer>
<?php wp_footer(); ?>
</body>
</html>
wp_head() and wp_footer() are essential: plugins, SEO tags, the admin bar and enqueued assets all depend on them.
Step 4: index.php and the loop
<?php get_header(); ?>
<?php if ( have_posts() ) : ?>
<?php while ( have_posts() ) : the_post(); ?>
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
<?php the_excerpt(); ?>
</article>
<?php endwhile; ?>
<?php the_posts_pagination(); ?>
<?php else : ?>
<p><?php esc_html_e( 'Nothing found.', 'tle-starter' ); ?></p>
<?php endif; ?>
<?php get_footer(); ?>
Activate the theme now; you have a working site.
Step 5: Add templates
singular.phporsingle.php+page.php: full content withthe_content(),the_post_thumbnail()andcomments_template().archive.php:the_archive_title()andthe_archive_description()above the loop.search.phpand404.php.template-parts/content.php, loaded withget_template_part(), to avoid repeating markup.
Which file is used when is explained in the template hierarchy.
Step 6: Widgets and editor styles
Register sidebars if your design needs them (register_sidebar). Add add_theme_support( 'editor-styles' ) and add_editor_style( 'editor.css' ) so content looks the same in the block editor. A small theme.json can also define colors, font sizes and content width for the editor even in a classic theme.
Step 7: Security and quality
- Escape all output:
esc_html(),esc_attr(),esc_url(),wp_kses_post(). - Make strings translatable with a text domain (translation-ready themes).
- Follow accessibility basics: skip link, focus styles, semantic landmarks, contrast (accessible themes).
- Responsive images through
the_post_thumbnail(), which outputssrcset.
Step 8: Test before launch
Install the Theme Check plugin, import the official theme unit test data, test with WP_DEBUG on, check on mobile and run Lighthouse. The full list is in the theme development checklist.
Common mistakes
- Forgetting
wp_head()orwp_footer(), which breaks plugins. - Hard-coding the
<title>tag instead of usingtitle-tagsupport. - Putting site features (custom post types, shortcodes) in the theme; they belong in a plugin.
- Unescaped output and untranslatable strings.
Frequently asked questions
What files are required for a WordPress theme?
A classic theme needs style.css and index.php. A block theme needs style.css and templates/index.html.
Should I start from a starter theme?
Starter themes save time and include good defaults. Building once from scratch is worth it to understand what they do.
Do I need to know PHP to build a theme?
For classic themes, yes, basic PHP. Block themes need mostly HTML, CSS and JSON.
Is a custom theme better for SEO?
It can be: a lean theme with clean markup and only the assets you need is usually faster than a multipurpose theme.
Conclusion
Start with the two required files, add theme supports and properly enqueued assets, build out templates following the hierarchy, and finish with escaping, translation, accessibility and testing. References: the Theme Handbook and style.css header requirements.
Want a custom theme built for speed and SEO? See our theme development service.
Save this practical guide
Add us as a preferred Google source, or ask an AI assistant to summarize this page and link back to the original guide when it is useful.
