wordpress theme development tutorial 2024
Published:
November 2025*
—
Introduction
Creating a custom WordPress theme gives you full control over the look, feel, and functionality of a website. Whether you’re a freelance developer, an agency professional, or a hobbyist eager to showcase your design skills, a **WordPress theme development tutorial 2024** must cover the latest core updates, Gutenberg block integration, and modern development workflows.
In this tutorial you will learn:
- How to set up a local development environment for WordPress 6.5 (the current LTS version).
- The essential file structure and template hierarchy for a 2024‑ready theme.
- Best practices for using `functions.php`, the Theme Customizer, and the new Block‑based Theme JSON.
- Techniques for responsive design, accessibility, and performance optimization.
By the end of this guide you’ll have a fully functional, SEO‑friendly theme ready to launch on any WordPress site.
—
Table of Contents
1. [Prerequisites & Tools](#prerequisites–tools)
2. [Setting Up the Development Environment](#setting-up-the-development-environment)
3. [Creating the Theme Folder & Core Files](#creating-the-theme-folder–core-files)
4. [Understanding the Template Hierarchy (2024 Edition)](#understanding-the-template-hierarchy-2024-edition)
5. [Building the `functions.php` File](#building-the-functionsphp-file)
6. [Integrating the Theme Customizer & Block‑Based Features](#integrating-the-theme-customizer–block‑based-features)
7. [Styling with CSS, SCSS, and the New `theme.json`](#styling-with-css-scss-and-the-new-themejson)
8. [Adding Gutenberg Blocks to Your Theme](#adding-gutenberg-blocks-to-your-theme)
9. [Responsive Design & Accessibility Checklist](#responsive-design–accessibility-checklist)
10. [Testing, Debugging, and Performance Optimization](#testing-debugging-and-performance-optimization)
11. [Deploying the Theme to a Live Site](#deploying-the-theme-to-a-live-site)
12. [Best Practices & SEO Tips for 2024](#best-practices–seo-tips-for-2024)
13. [FAQ](#faq)
14. [Conclusion](#conclusion)
—
Prerequisites & Tools
Before diving into the **WordPress theme development tutorial 2024**, make sure you have the following:
- **Local server** – XAMPP, MAMP, LocalWP, or Docker with PHP 8.2+.
- **Code editor** – VS Code, Sublime Text, or PHPStorm with WordPress extensions.
- **Command‑line tools** – Node.js 20+, npm/yarn, and WP‑CLI.
- **Version control** – Git (GitHub or GitLab for remote repos).
- **Design assets** – Sketch, Figma, or Adobe XD files for mockups.
Optional but recommended*:
- **Sass/SCSS compiler** (e.g., `sass` CLI).
- **ESLint & Stylelint** for JavaScript and CSS linting.
—
Setting Up the Development Environment
1. **Install WordPress locally**
“`bash
wp core download –locale=en_US
wp config create –dbname=wp_theme_demo –dbuser=root –dbpass=secret
wp db create
wp core install –url=”http://localhost/wp_theme_demo” –title=”Theme Demo” –admin_user=”admin” –admin_password=”password” –admin_email=”admin@example.com”
“`
2. **Create a new theme directory**
“`bash
mkdir wp-content/themes/my‑awesome‑theme
cd wp-content/themes/my‑awesome‑theme
“`
3. **Initialize Git**
“`bash
git init
git add .
git commit -m “Initial commit – empty theme scaffold”
“`
4. **Set up npm for asset bundling** (optional but modern)
“`bash
npm init -y
npm install –save-dev webpack webpack-cli sass-loader css-loader style-loader
“`
—
Creating the Theme Folder & Core Files
Your theme needs at least these files to be recognized by WordPress:
- `style.css` – contains the theme header comment.
- `functions.php` – registers scripts, styles, and theme supports.
- `index.php` – fallback template.
Example `style.css` header
“`css
/*
Theme Name: My Awesome Theme
Theme URI: https://example.com/my-awesome-theme
Author: Your Name
Author URI: https://example.com
Description: A modern, block‑based WordPress theme for 2024.
Version: 1.0.0
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html
Text Domain: my-awesome-theme
Tags: block-theme, responsive-layout, custom-colors
*/
“`
Minimal `index.php`
“`php
<?php
// Exit if accessed directly.
defined( ‘ABSPATH’ ) || exit;
get_header();
if ( have_posts() ) :
while ( have_posts() ) : the_post();
the_content();
endwhile;
else :
echo ‘<p>’ . __( ‘No content found.’, ‘my-awesome-theme’ ) . ‘</p>’;
endif;
get_footer();
“`
—
Understanding the Template Hierarchy (2024 Edition)
WordPress 6.5 introduced **full site editing (FSE)** as the default for new themes. The hierarchy now includes:
- `theme.json` – global styling & settings.
- `block‑templates/` – HTML files for site parts (header, footer, archive, single).
- `parts/` – reusable block parts (e.g., `header.html`, `footer.html`).
*Classic hierarchy** (still supported) remains for backward compatibility:
- `header.php`, `footer.php`, `sidebar.php`, `single.php`, `page.php`, `archive.php`, `search.php`, `404.php`.
When building a **WordPress theme development tutorial 2024**, focus on the block‑based approach, then add classic PHP templates as fallbacks.
—
Building the `functions.php` File
The `functions.php` file is the engine of your theme. Below is a concise starter that covers the essentials for 2024.
“`php
<?php
if ( ! defined( ‘ABSPATH’ ) ) {
exit; // Prevent direct access.
}
/**
- Theme setup.
*/
function my_awesome_theme_setup() {
// Add support for block styles and full site editing.
add_theme_support( ‘block-templates’ );
add_theme_support( ‘wp-block-styles’ );
add_theme_support( ‘align-wide’ );
add_theme_support( ‘responsive-embeds’ );
add_theme_support( ‘editor-styles’ );
// Load editor stylesheet.
add_editor_style( ‘style-editor.css’ );
// Register navigation menus.
register_nav_menus( array(
‘primary’ => __( ‘Primary Menu’, ‘my-awesome-theme’ ),
) );
// Add support for custom logo.
add_theme_support( ‘custom-logo’, array(
‘height’ => 80,
‘width’ => 250,
‘flex-height’ => true,
‘flex-width’ => true,
) );
}
add_action( ‘after_setup_theme’, ‘my_awesome_theme_setup’ );
/**
- Enqueue front‑end scripts and styles.
*/
function my_awesome_theme_assets() {
// Main stylesheet.
wp_enqueue_style(
‘my-awesome-theme-style’,
get_stylesheet_uri(),
array(),
wp_get_theme()->get( ‘Version’ )
);
// Optional: compiled CSS from SCSS.
wp_enqueue_style(
‘my-awesome-theme-main’,
get_template_directory_uri() . ‘/assets/css/main.css’,
array(),
wp_get_theme()->get( ‘Version’ )
);
// Main JavaScript bundle.
wp_enqueue_script(
‘my-awesome-theme-script’,
get_template_directory_uri() . ‘/assets/js/bundle.js’,
array( ‘jquery’ ),
wp_get_theme()->get( ‘Version’ ),
true
);
}
add_action( ‘wp_enqueue_scripts’, ‘my_awesome_theme_assets’ );
“`
*Key takeaways for the tutorial**:
- Use `add_theme_support()` to enable modern features.
- Register menus and custom logo for flexibility.
- Enqueue assets with version numbers tied to the theme version for cache busting.
—
Integrating the Theme Customizer & Block‑Based Features
1. Theme Customizer (Classic)
Add a simple section for accent color:
“`php
function my_awesome_customize_register( $wp_customize ) {
$wp_customize->add_section( ‘my_awesome_colors’, array(
‘title’ => __( ‘Theme Colors’, ‘my-awesome-theme’ ),
‘priority’ => 30,
) );
$wp_customize->add_setting( ‘accent_color’, array(
‘default’ => ‘#0066cc’,
‘transport’ => ‘postMessage’,
) );
$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, ‘accent_color’, array(
‘label’ => __( ‘Accent Color’, ‘my-awesome-theme’ ),
‘section’ => ‘my_awesome_colors’,
) ) );
}
add_action( ‘customize_register’, ‘my_awesome_customize_register’ );
“`
2. `theme.json` – The 2024 Powerhouse
Create a `theme.json` file in the root of your theme:
“`json
{
“version”: 2,
“settings”: {
“color”: {
“custom”: false,
“customDuotone”: false,
“palette”: [
{
“slug”: “primary”,
“color”: “#0066cc”,
“name”: “Primary”
},
{
“slug”: “secondary”,
“color”: “#ff6600”,
“name”: “Secondary”
}
]
},
“typography”: {
“customFontSize”: false,
“fontFamilies”: [
{
“fontFamily”: “\”Inter\”, system-ui, sans-serif”,
“name”: “Inter”,
“slug”: “inter”
}
]
},
“spacing”: {
“customPadding”: false,
“customMargin”: false,
“units”: [ “px”, “rem”, “%” ]
}
},
“styles”: {
“color”: {
“background”: “#ffffff”,
“text”: “#333333”
},
“spacing”: {
“padding”: { “top”: “2rem”, “bottom”: “2rem” }
}
}
}
“`
- `theme.json` centralizes design tokens, reduces CSS bloat, and improves performance—crucial for **SEO‑optimized WordPress theme development tutorial 2024**.
—
Styling with CSS, SCSS, and the New `theme.json`
1. **SCSS workflow** – Organize your source files:
“`
assets/
├─ scss/
│ ├─ base/_reset.scss
│ ├─ components/_buttons.scss
│ ├─ layout/_header.scss
│ └─ main.scss
└─ css/
└─ main.css (compiled output)
“`
2. **Compile SCSS** (example npm script):
“`json
“scripts”: {
“scss”: “sass assets/scss/main.scss assets/css/main.css –no-source-map –style=compressed”
}
“`
3. **Leverage `theme.json` variables** – Use CSS custom properties generated automatically, e.g., `var(–wp–preset–color–primary)`.
4. **Add a fallback `style-editor.css`** for the block editor, mirroring front‑end styles.
—
Adding Gutenberg Blocks to Your Theme
Register a Simple Dynamic Block
“`php
function my_awesome_register_blocks() {
// Register block script.
wp_register_script(
‘my-awesome-block’,
get_template_directory_uri() . ‘/assets/js/block.js’,
array( ‘wp-blocks’, ‘wp-element’, ‘wp-editor’ ),
wp_get_theme()->get( ‘Version’ ),
true
);
// Register block type.
register_block_type( ‘my-awesome/banner’, array(
‘editor_script’ => ‘my-awesome-block’,
‘render_callback’ => ‘my_awesome_render_banner’,
‘attributes’ => array(
‘title’ => array(
‘type’ => ‘string’,
‘default’ => __( ‘Welcome!’, ‘my-awesome-theme’ ),
),
‘backgroundColor’ => array(
‘type’ => ‘string’,
‘default’ => ‘primary’,
),
),
) );
}
add_action( ‘init’, ‘my_awesome_register_blocks’ );
function my_awesome_render_banner( $attributes ) {
$title = esc_html( $attributes[‘title’] );
$bg = esc_attr( $attributes[‘backgroundColor’] );
return “<section class=’my-banner has-{$bg}-background-color
About Relvixis: Relvixis is a Canadian-based digital agency specializing in results-driven solutions for businesses looking to grow online.
We offer expert services in SEO optimization, web development, social media management, and marketing automation.
Our team blends creative strategy with technical precision to drive leads, enhance brand visibility, and accelerate digital performance.
To learn more or schedule a free consultation, visit
relvixis.com.
