Installing WordPress and Creating Your First Custom Theme

If you want to become a WordPress theme developer, the best way to learn is by creating a simple custom theme from scratch. In this guide, you’ll learn the basics of WordPress theme development step by step in a beginner-friendly way.

1. Installing WordPress

Before creating a custom theme, you need a working WordPress installation.

Requirements

You need:

  • PHP
  • MySQL or MariaDB
  • Apache/Nginx server
  • Local server software like:
    • XAMPP
    • WAMP
    • LocalWP
    • Laragon

Download WordPress

Download WordPress from:

WordPress Official Website

Extract the files into your local server directory.

Example:

htdocs/mywebsite

Create Database

Open phpMyAdmin and create a database:

mywebsite_db

Run Installation

Visit:

http://localhost/mywebsite

Then:

  1. Select language
  2. Enter DB details
  3. Create admin username/password
  4. Finish installation

Your WordPress site is ready.


2. Default WordPress Database Tables

A fresh WordPress installation creates 12 default tables.

Table NamePurpose
wp_postsStores posts, pages, attachments
wp_postmetaStores post custom fields
wp_usersUser accounts
wp_usermetaUser metadata
wp_commentsComments
wp_commentmetaComment metadata
wp_termsCategories & tags
wp_termmetaTaxonomy metadata
wp_term_taxonomyTaxonomy details
wp_term_relationshipsRelation between posts & taxonomy
wp_optionsWebsite settings
wp_linksOld blogroll links

Prefix wp_ may change during installation.


3. Creating Your First Custom Theme

Themes are stored inside:

wp-content/themes/

Create Theme Folder

Create a folder:

my-first-theme

Inside it create:

style.css
index.php
screenshot.png

4. Add Theme Details in style.css

WordPress identifies themes using the comment block in style.css.

style.css

/*
Theme Name: My First Theme
Theme URI: https://example.com
Author: John Doe
Author URI: https://example.com
Description: My first custom WordPress theme
Version: 1.0
*/

You can also add CSS below this block.


5. Create index.php File

index.php is the main template file.

Basic Example

<?php get_header(); ?>

<h1>My Blog</h1>

<?php
if ( have_posts() ) :

while ( have_posts() ) :
the_post();
?>

<h2><?php the_title(); ?></h2>

<div>
<?php the_content(); ?>
</div>

<?php
endwhile;

else :
echo "<p>No posts found.</p>";

endif;
?>

<?php get_footer(); ?>

This is called the WordPress Loop.


6. Add Theme Screenshot

Add an image named:

screenshot.png

Recommended size:

1200 x 900 px

This image appears in WordPress admin under:

Appearance → Themes

7. Activate the Theme

Go to:

Dashboard → Appearance → Themes

Activate your custom theme.


8. Import Dummy Content

When learning theme development, dummy content helps test layouts.

Install WordPress Importer

Go to:

Tools → Import → WordPress

Install and run importer.

Download Dummy Data

Use official test data:

WordPress Theme Unit Test Data

Import the XML file.

Now your site contains:

  • Posts
  • Images
  • Menus
  • Nested comments
  • Long titles

Perfect for testing themes.


9. Understanding Template Partials

Instead of writing all HTML in one file, WordPress separates reusable parts.

Common Template Partials

FilePurpose
header.phpHeader section
footer.phpFooter section
sidebar.phpSidebar
index.phpMain template

header.php

<!DOCTYPE html>
<html <?php language_attributes(); ?>>

<head>
<meta charset="<?php bloginfo('charset'); ?>">
<title><?php bloginfo('name'); ?></title>

<?php wp_head(); ?>
</head>

<body <?php body_class(); ?>>

<header>
<h1><?php bloginfo('name'); ?></h1>
</header>

footer.php

<footer>
<p>Copyright 2026</p>
</footer>

<?php wp_footer(); ?>

</body>
</html>

sidebar.php

<aside>
<h3>Sidebar</h3>
</aside>

Include Partials in index.php

<?php get_header(); ?>

<?php get_sidebar(); ?>

<?php get_footer(); ?>

WordPress automatically loads:

  • header.php
  • sidebar.php
  • footer.php

10. VS Code Extensions for WordPress Development

Using extensions improves productivity.

Recommended Extensions

PHP Intelephense

Provides:

  • Auto completion
  • Function suggestions
  • Error checking

PHP Intelephense Extension


WordPress Snippets

Provides ready-made WordPress snippets.

WordPress Snippets Extension


PHP Namespace Resolver

Automatically imports classes and namespaces.

PHP Namespace Resolver Extension


11. Understanding the WordPress Loop

The Loop is how WordPress fetches posts.

Example

<?php

if ( have_posts() ) :

while ( have_posts() ) :
the_post();

the_title();
the_excerpt();

endwhile;

endif;

?>

What Happens Internally?

FunctionPurpose
have_posts()Checks if posts exist
the_post()Loads current post
the_title()Displays title
the_content()Displays content

12. About get_* Functions

WordPress has many get_* functions.

Examples:

get_the_title()
get_the_content()
get_permalink()

These functions usually return data.


When to Use echo?

Use echo with get_* functions

echo get_the_title();

Because get_the_title() returns value.


No echo Needed

Functions starting with the_ usually print directly.

the_title();

Wrong:

echo the_title();

Easy Rule

Function TypeBehavior
get_*Returns value
the_*Prints value

13. WP_Query()

WP_Query is used for custom queries.

Example

<?php

$args = array(
'post_type' => 'post',
'posts_per_page' => 5
);

$custom_query = new WP_Query($args);

if ( $custom_query->have_posts() ) :

while ( $custom_query->have_posts() ) :
$custom_query->the_post();

the_title();

endwhile;

endif;

wp_reset_postdata();

?>

Why wp_reset_postdata()?

Custom queries modify global post data.

After loop finishes:

wp_reset_postdata();

restores original query.

Without resetting, other template tags may behave incorrectly.


14. WordPress Template Hierarchy

Template hierarchy decides which file WordPress loads.

Examples

Page TypeTemplate Used
Home pagehome.php
Single postsingle.php
Pagepage.php
Category archivecategory.php
404 page404.php

If file does not exist, WordPress falls back to:

index.php

Example Flow

For a blog post:

single.php

singular.php

index.php

Useful Resource

WordPress Template Hierarchy Guide


15. functions.php and Helper Functions

functions.php works like the theme’s engine.

Used for:

  • Theme setup
  • Menus
  • Scripts/styles
  • Custom helper functions

Example

<?php

function mytheme_setup() {

add_theme_support('post-thumbnails');

register_nav_menus(array(
'primary-menu' => 'Primary Menu'
));
}

add_action('after_setup_theme', 'mytheme_setup');

Custom Helper Function

function get_reading_time($content) {

$word_count = str_word_count(strip_tags($content));

$reading_time = ceil($word_count / 200);

return $reading_time;
}

Usage:

echo get_reading_time(get_the_content());

16. Validation, Sanitization, and Escaping

These are very important for WordPress security.


Validation

Checks if input is correct.

Example:

if ( is_email($email) ) {
echo "Valid Email";
}

Sanitization

Cleans data before saving.

Examples

sanitize_text_field($_POST['name']);

sanitize_email($_POST['email']);

Escaping

Escaping protects output before displaying.

Examples

echo esc_html($name);

echo esc_url($website);

echo esc_attr($value);

Simple Flow

User Input

Validation

Sanitization

Save to DB

Escaping before Output

17. Internationalization (i18n) & Localization (l10n)

These help make themes translatable.


Internationalization (i18n)

Writing code ready for translation.

Example

<?php _e('Read More', 'mytheme'); ?>

or

echo __('Read More', 'mytheme');

Localization (l10n)

Translating text into another language.

Example:

English → Hindi
English → Gujarati
English → French

Load Theme Text Domain

Inside functions.php

function mytheme_load_textdomain() {

load_theme_textdomain(
'mytheme',
get_template_directory() . '/languages'
);
}

add_action(
'after_setup_theme',
'mytheme_load_textdomain'
);

Final Thoughts

When learning WordPress theme development, focus on these fundamentals first:

  • Theme structure
  • WordPress loop
  • Template hierarchy
  • functions.php
  • Security practices
  • Custom queries
  • Translation support

Do not try to learn everything at once. Build small themes first, experiment with template files, and gradually move toward advanced topics like:

  • Custom Post Types
  • Gutenberg blocks
  • Advanced Custom Fields
  • WooCommerce themes
  • REST API
  • Full Site Editing (FSE)

Once your basics are strong, WordPress theme development becomes much easier and more enjoyable.