In this Q&A exchange we walk through creating a simple WordPress theme boilerplate. You will learn the roles of style.css, index.php, functions.php and the header and footer templates. Ready to kickstart theme development with clean, organized files?
Write me some boilerplate for a WordPress theme
Here’s a basic WordPress theme boilerplate with the essential files and minimal structure:
Files Included:
style.css – theme metadata and main stylesheetindex.php – main template filefunctions.php – theme setup and asset registrationheader.php – document head and opening markupfooter.php – closing markup and footer contentstyle.css
/*
Theme Name: Basic Theme
Theme URI: https://www.example.com/
Description: A basic WordPress theme.
Version: 1.0.0
Author: Your Name
Author URI: https://www.example.com/
License: GNU General Public License v2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
Text Domain: basic-theme
*/
index.php
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title><?php bloginfo('name'); ?></title>
<?php wp_head(); ?>
</head>
<body >
<div id="page" class="site">
<header id="masthead" class="site-header">
<div class="site-branding">
<a href="<?php echo esc_url( home_url('/') ); ?>" class="site-title"><?php bloginfo('name'); ?></a>
<p class="site-description"><?php bloginfo('description'); ?></p>
</div>
<nav id="site-navigation" class="main-navigation">
<?php
wp_nav_menu(array(
'theme_location' => 'menu-1',
'menu_id' => 'primary-menu',
));
?>
</nav>
</header>
<div id="content" class="site-content">
<main id="primary" class="content-area">
<?php
if ( have_posts() ) :
while ( have_posts() ) : the_post();
get_template_part( 'template-parts/content', get_post_type() );
endwhile;
else :
echo '<p>No content found.</p>';
endif;
?>
</main>
</div>
<footer id="colophon" class="site-footer">
<div class="site-info">
<?php
printf(
esc_html__( 'Theme: %1$s by %2$s.', 'basic-theme' ),
'Basic Theme',
'<a href="https://www.example.com/">Your Name</a>'
);
?>
</div>
</footer>
</div>
<?php wp_footer(); ?>
</body>
</html>
functions.php
<?php
function basic_theme_setup() {
add_theme_support( 'title-tag' );
add_theme_support( 'post-thumbnails' );
register_nav_menus( array(
'menu-1' => esc_html__( 'Primary Menu', 'basic-theme' ),
) );
add_theme_support( 'html5', array( 'search-form', 'comment-form', 'comment-list', 'gallery', 'caption' ) );
add_theme_support( 'custom-logo', array(
'height' => 250,
'width' => 250,
'flex-width' => true,
'flex-height' => true,
) );
}
add_action( 'after_setup_theme', 'basic_theme_setup' );
function basic_theme_widgets_init() {
register_sidebar( array(
'name' => esc_html__( 'Sidebar', 'basic-theme' ),
'id' => 'sidebar-1',
'description' => esc_html__( 'Add widgets here.', 'basic-theme' ),
'before_widget' => '<section id="%1$s" class="widget %2$s">',
'after_widget' => '</section>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
) );
}
add_action( 'widgets_init', 'basic_theme_widgets_init' );
function basic_theme_scripts() {
wp_enqueue_style( 'basic-theme-style', get_stylesheet_uri() );
wp_enqueue_script( 'basic-theme-navigation', get_template_directory_uri() . '/js/navigation.js', array(), '1.0.0', true );
}
add_action( 'wp_enqueue_scripts', 'basic_theme_scripts' );
?>
header.php
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title><?php wp_title('|', true, 'right'); ?></title>
<?php wp_head(); ?>
</head>
<body >
footer.php
<footer>
<p>© <?php echo date('Y'); ?> <?php bloginfo('name'); ?></p>
</footer>
<?php wp_footer(); ?>
</body>
</html>
Important Notes:
basic-theme) under wp-content/themes/.template-parts/content.php and template-parts/content-page.php for better organization.WP Assistant is a free tool created by Atiba Software, a WordPress design and development company located in Nashville, TN. If you need more personalized WordPress assistance let us know, and we’ll get back to you ASAP!