This guide walks you through building a classic WordPress theme from zero files to a working, styled site. You’ll create the required template files, add basic styling, and understand how WordPress connects your theme to its content. You’ll need a local or hosted WordPress installation, a code editor, and basic knowledge of HTML, CSS, and PHP.
What You’ll Need
- A WordPress installation (local like LocalWP, or a staging site).
- A code editor (VS Code, Sublime Text, or similar).
- Basic understanding of PHP, HTML, and CSS.
- File access to the WordPress directory (via FTP or file manager).
Step-by-Step
- Set up your theme folder. Navigate to
wp-content/themes/and create a new folder, e.g.,myclassic. All your theme files go here. - Create the stylesheet (style.css). This is the main stylesheet and the theme’s header. At the top, add the required comment block:
/* Theme Name: My Classic Theme URI: https://example.com/myclassic Author: Your Name Description: A simple classic WordPress theme. Version: 1.0 License: GPL v2 or later Text Domain: myclassic */
This header is required for WordPress to recognize the theme.
- Create the main template file (index.php). This is the fallback template for all views. Start with a basic loop that displays posts:
<?php get_header(); ?> <main> <?php if ( have_posts() ) : ?> <?php while ( have_posts() ) : the_post(); ?> <article> <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2> <div><?php the_content(); ?></div> </article> <?php endwhile; ?> <?php endif; ?> </main> <?php get_sidebar(); ?> <?php get_footer(); ?>This loop fetches posts and displays them.
- Create header.php. This file contains the top part of your site: the doctype, head, and opening body tags. Include calls to
wp_head()andwp_body_open():<!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(); ?> <header> <h1><a href="<?php echo esc_url(home_url('/')); ?>"><?php bloginfo('name'); ?></a></h1> <p><?php bloginfo('description'); ?></p> </header>The
wp_head()function is critical for plugins and styles. - Create footer.php. This closes the body and includes
wp_footer():<footer> <p>© <?php echo date('Y'); ?> <?php bloginfo('name'); ?></p> </footer> <?php wp_footer(); ?> </body> </html>wp_footer()is required for scripts and plugins. - Add functions.php. This file enables theme features and enqueues styles/scripts. Start with the basics:
<?php function myclassic_setup() { add_theme_support('title-tag'); add_theme_support('post-thumbnails'); register_nav_menus(array('primary' => 'Primary Menu')); } add_action('after_setup_theme', 'myclassic_setup'); function myclassic_scripts() { wp_enqueue_style('myclassic-style', get_stylesheet_uri()); } add_action('wp_enqueue_scripts', 'myclassic_scripts'); ?>This adds title support, featured images, a menu location, and loads your style.css.
- Create a navigation menu (optional but recommended). In header.php, add a menu area using
wp_nav_menu():<nav> <?php wp_nav_menu(array('theme_location' => 'primary')); ?> </nav>Then assign a menu in the WordPress admin under Appearance > Menus.
- Add template hierarchy files. To make your theme more functional, create
single.phpfor single posts,page.phpfor pages, andarchive.phpfor archives. Start by copying index.php and adjusting the loop. For example, single.php can show the post title, date, and content, and add comments. - Create a sidebar (optional). Create
sidebar.phpand register it in functions.php:function myclassic_widgets_init() { register_sidebar(array( 'name' => 'Sidebar', 'id' => 'sidebar-1', 'before_widget' => '<div id="%1$s" class="widget %2$s">', 'after_widget' => '</div>', )); } add_action('widgets_init', 'myclassic_widgets_init');Then in sidebar.php, call
dynamic_sidebar('sidebar-1'). - Add basic styling. In style.css, after the header comment, add CSS to make your theme look decent. Start with a simple reset, typography, and layout for header, content, sidebar, and footer.
- Test your theme. In the WordPress admin, go to Appearance > Themes and activate “My Classic”. Visit your site to see it working. Check that the header, footer, and content display correctly.
- Add a screenshot (optional). Create a 1200×900 PNG named
screenshot.pngand place it in your theme folder. It will appear in the theme selector.
Common Mistakes
- Forgetting the style.css header comment – WordPress won’t recognize the theme.
- Missing
wp_head()orwp_footer()– breaks plugins and styling. - Using the wrong text domain in translations.
- Not escaping output (e.g., using
the_title()withoutesc_html()in attributes). - Hardcoding URLs instead of using
home_url()orget_template_directory_uri(). - Forgetting to call
wp_enqueue_style()– styles won’t load.
Tips
- Use a child theme for customizations if you plan to update the parent theme.
- Start with the WordPress Theme Handbook – it’s the official reference.
- Use browser developer tools to inspect elements and debug CSS.
- Keep your code modular: separate header, footer, and sidebar into files.
- Use
get_template_part()to reuse code blocks like loops. - Add support for common features like custom logo, custom background, and HTML5.
Troubleshooting
Theme not appearing in admin: Check that style.css has the correct header comment and is in the right folder. Ensure the file is saved with UTF-8 encoding.
No styles loading: Verify you enqueued the stylesheet in functions.php. Check the browser’s network tab to see if style.css is requested and if the path is correct.
Blank page: This is often a PHP error. Enable WP_DEBUG in wp-config.php (set to true) to see error messages. Check your PHP syntax.
Menus not showing: Ensure you registered the menu location and assigned a menu in Appearance > Menus. Also, check that the menu location name matches.
Sidebar not appearing: Make sure you called get_sidebar() in your template and registered the sidebar in functions.php. Check that widgets are added in Appearance > Widgets.
Posts not displaying: Verify the loop in index.php is correct. Check that you have posts published in the admin.
Frequently Asked Questions
Do I need to know PHP to create a WordPress theme?
Yes, basic PHP is required because WordPress themes are PHP files. You can start with simple templates and learn as you go.
What is the difference between a classic theme and a block theme?
A classic theme uses PHP templates and the WordPress Loop, while a block theme uses HTML templates and blocks. Classic themes are more traditional and give you full control over markup.
Can I create a theme without a page builder?
Absolutely. A classic theme works without a page builder, and you can add page builder support later if needed.
How do I add custom post types to my theme?
You can register custom post types in functions.php using register_post_type(). Then create templates like single-{post_type}.php to display them.
Is it better to build a theme from scratch or use a framework?
Building from scratch gives you full control and a lighter theme. Frameworks like Underscores provide a starter structure, which can speed up development.
How do I update my theme safely?
Use a child theme for updates. If you update the parent theme directly, your changes will be lost. Always back up your files before updating.
Related
Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.
More cards in this drawer
- Valheim Server Not Showing in Community List Fixes
- DisplayPort vs HDMI: Which Cable Should You Use?
- Soundbar vs 2.1 Speaker System: Which Is Better?
- Survive Lava for Brainrot Tier List170 points
- MySQL Dump Import: Fix Common Errors
- Mouse Moving on Its Own? Causes & Fixes