Build classic and block WordPress themes from scratch: the template hierarchy, The Loop, the_title() and the_content(), template parts, menus, the Customizer, child themes and theme.json.
Lessons
A custom page template is a PHP file with a special Template Name: comment that site owners can assign to any page from the editor — the standard way to give a landing page, contact page or full-width page its own layout.
Create page-templates/full-width.php:
<?php
/**
* Template Name: Full Width
* Template Post Type: page, post
*
* A page with no sidebar, content spanning the full container.
*/
get_header();
?>
<main id="main" class="site-main site-main--full-width">
<?php while ( have_posts() ) : the_post(); ?>
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<header class="entry-header">
<?php the_title( '<h1 class="entry-title">', '</h1>' ); ?>
</header>
<?php if ( has_post_thumbnail() ) : ?>
<figure class="entry-hero">
<?php the_post_thumbnail( 'full' ); ?>
</figure>
<?php endif; ?>
<div class="entry-content">
<?php
the_content();
wp_link_pages(
array(
'before' => '<nav class="page-links">' . esc_html__( 'Pages:', 'gdc-starter' ),
'after' => '</nav>',
)
);
?>
</div>
</article>
<?php
if ( comments_open() || get_comments_number() ) {
comments_template();
}
?>
<?php endwhile; ?>
</main>
<?php
get_footer();Open any page in the editor. In the Template panel of the page settings sidebar, "Full Width" is now an option. Choose it and the page renders with this file.
Template Name: is required — it is the label shown in the editor and how WordPress finds the file.Template Post Type: (WordPress 4.7+) makes the template available to other post types. Leave it out and it applies to pages only.page-templates/ folder keeps the root tidy.Page templates are where the_title() and the_content() combine with your own markup. Here the title becomes a hero heading, and the page content fills a centred column below a call-to-action band:
<?php
/**
* Template Name: Landing Page
*/
get_header( 'minimal' );
?>
<main id="main" class="landing">
<?php while ( have_posts() ) : the_post(); ?>
<section class="landing__hero">
<?php the_title( '<h1 class="landing__title">', '</h1>' ); ?>
<?php if ( has_excerpt() ) : ?>
<p class="landing__lead"><?php echo esc_html( get_the_excerpt() ); ?></p>
<?php endif; ?>
<a class="button button--primary" href="<?php echo esc_url( home_url( '/contact/' ) ); ?>">
<?php esc_html_e( 'Get in touch', 'gdc-starter' ); ?>
</a>
</section>
<section class="landing__body">
<div class="entry-content">
<?php the_content(); ?>
</div>
</section>
<?php endwhile; ?>
</main>
<?php
get_footer();The page excerpt doubles as the hero's lead sentence. Enable excerpts for pages with add_post_type_support( 'page', 'excerpt' ); in your setup function so the owner can edit it.
| Use | When |
|---|---|
| A page template | The owner should be able to choose the layout, on any number of pages. |
page-{slug}.php | Exactly one page needs a unique layout and the owner should not be able to change it. |
To load a script only on landing pages, test the template file name:
<?php
if ( is_page_template( 'page-templates/landing.php' ) ) {
wp_enqueue_script( 'gdc-starter-landing', get_template_directory_uri() . '/assets/js/landing.js', array(), GDC_STARTER_VERSION, true );
}Template Post Type: page, post.In accordance with Section 6 & Section 7 of the DPDP Act 2023, third-party analytics and marketing trackers are strictly gated behind your affirmative consent. You may withdraw consent at any time under Section 6(4).
Essential for session authentication (ci_session), Cross-Site Request Forgery security (csrf_cookie_name), and Cloudflare DDoS/bot prevention. Cannot be disabled.
Gated under DPDP Section 7. Allows Google Analytics 4 (Google Consent Mode v2) to measure aggregate, anonymized tool usage.
Enables browser local storage to preserve your theme selection (dark/light mode) and code editor layout between visits.
Used to display developer sponsorships and native tool partner notices.