
If you’re coming from a static HTMLHTML (HyperText Markup Language) The standard markup languag... More background, WordPress can feel confusing at first. You create an about-us.html file, upload it to your server, and expect it to work like a normal webpage. But when you try to access it, something feels off. The styling is missing, WordPress features don’t work, and you realize you’re outside the system entirely.
Here’s the fundamental shift you need to make: WordPress doesn’t serve static files from your disk. Every postDynamic, time-based content (e.g., blog entries) displayed i... More, pageStatic content (e.g., "About Us," "Contact") not part of chr... More, and piece of content lives in the databaseWhere all WordPress content, settings, and user data are sto... More. The templateTemplate A file in a theme that defines how different parts ... More files you create are blueprints, not standalone pages. WordPress loads its engine, grabs the content from the databaseWhere all WordPress content, settings, and user data are sto... More, and pours it into those templates before sending the result to the browser.
This architecture is powerful, but it requires a different mental model. Let’s walk through how to properly add custom templates, include them in your themeTheme A collection of files that determine a site's design, ... More, and link to them without breaking everything.
Consider this scenario. You create a file called about-us.php in your themeTheme A collection of files that determine a site's design, ... More folder and upload it. You then try to visit yoursite.com/wp-content/themes/yourtheme/about-us.php.
What happens? The file loads, but it has no access to WordPress functions. get_header() fails. Your menuMenu A collection of links (to pages, categories, or custom ... More doesn’t appear. Your styling is missing. The user session and login status are invisible. You are essentially standing outside the house looking through the window.
Why this fails: When you access a PHP file directly, the WordPress coreCore The foundational files and code of WordPress itself, ma... More never loads. No databaseWhere all WordPress content, settings, and user data are sto... More connection, no query, no templateTemplate A file in a theme that defines how different parts ... More hierarchy. You get a blank, lonely file with no context.
The correct approach is to create a pageStatic content (e.g., "About Us," "Contact") not part of chr... More templateTemplate A file in a theme that defines how different parts ... More that WordPress recognizes and can use to display content from the databaseWhere all WordPress content, settings, and user data are sto... More.
Step 1: Create Your TemplateTemplate A file in a theme that defines how different parts ... More File
In your themeTheme A collection of files that determine a site's design, ... More folder, create a file called about-us.php. At the very top, add this commentUser feedback or discussion attached to a post or page, mana... More block:
php
<?php
/**
* Template Name: About Us
*/
get_header();
?>
<div class="content-area">
<h1><?php the_title(); ?></h1>
<div class="entry-content">
<?php the_content(); ?>
</div>
</div>
<?php get_footer(); ?>This single comment—Template Name: About Us—tells WordPress this file exists and can be selected as a templateTemplate A file in a theme that defines how different parts ... More.
Step 2: Create the PageStatic content (e.g., "About Us," "Contact") not part of chr... More in AdminThe admin (administrator) is the highest user role with full... More
the_content() appears in your templateTemplate A file in a theme that defines how different parts ... More.Now when you view this pageStatic content (e.g., "About Us," "Contact") not part of chr... More, WordPress loads its engine, queries the databaseWhere all WordPress content, settings, and user data are sto... More for the pageStatic content (e.g., "About Us," "Contact") not part of chr... More content, and uses about-us.php as the blueprint. The URL will be something like yoursite.com/about-us (depending on your permalinkPermalink The permanent URL of a post, page, or other conten... More settings). Clean, secure, and fully integrated.
Sometimes you don’t want a full pageStatic content (e.g., "About Us," "Contact") not part of chr... More templateTemplate A file in a theme that defines how different parts ... More. You just want to include a reusable piece of code across multiple templates—a custom section, a complex loop, a specialized call-to-action block.
WordPress provides the get_template_part() function for exactly this purpose.
Step 1: Create the TemplateTemplate A file in a theme that defines how different parts ... More Part
Inside your themeTheme A collection of files that determine a site's design, ... More folder, create a subfolder called template-parts (this is a convention, not a requirement). Inside it, create a file called content-featured.php:
php
<?php
// template-parts/content-featured.php
?>
<div class="featured-section">
<h2>Featured Resources</h2>
<?php
$featured_posts = new WP_Query(array(
'posts_per_page' => 3,
'meta_key' => 'featured',
'meta_value' => 'yes'
));
if ($featured_posts->have_posts()) :
while ($featured_posts->have_posts()) : $featured_posts->the_post();
?>
<article>
<h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
<?php the_excerpt(); ?>
</article>
<?php endwhile;
wp_reset_postdata();
endif;
?>
</div>Step 2: Include It in Your Templates
Now, anywhere you want this featured section to appear, you call get_template_part():
php
<?php get_template_part('template-parts/content', 'featured'); ?>WordPress will look for template-parts/content-featured.php and include it. The function is smart—it allows for fallbacks and keeps your templates clean and modular.
Why This Matters: Instead of copying and pasting the same 20 lines of HTMLHTML (HyperText Markup Language) The standard markup languag... More and PHP across multiple templateTemplate A file in a theme that defines how different parts ... More files, you define it once and reuse it. When you need to update the design, you change one file. This is the professional way to build WordPress themes.
The Stack Overflow answer mentioned linking to a PHP file directly. Let’s be clear: you should never hardcode a link to a PHP file in your themeTheme A collection of files that determine a site's design, ... More. Those paths break when you change permalinks, move servers, or update your themeTheme A collection of files that determine a site's design, ... More.
Instead, use WordPress functions that generate URLs dynamically.
For Pages You Created:
php
<a href="<?php echo get_permalink(get_page_by_path('about-us')->ID); ?>">
About Us
</a>This looks up the pageStatic content (e.g., "About Us," "Contact") not part of chr... More by its slugThe URL-friendly version of a post/page title (e.g., my-awes... More (about-us) and returns its permalinkPermalink The permanent URL of a post, page, or other conten... More. Even if you change the URL structure later, this link continues to work.
For the Homepage:
php
<a href="<?php echo home_url(); ?>">Home</a>
For a Specific PageStatic content (e.g., "About Us," "Contact") not part of chr... More Using Its SlugThe URL-friendly version of a post/page title (e.g., my-awes... More:
php
<a href="<?php echo site_url('/about-us/'); ?>">About Us</a>The site_url() function returns your site’s base URL, and you append the path. This is simpler than the get_permalink() approach but slightly less dynamic. Both work.
Let’s walk through a full, production-ready example.
Step 1: Create about-us.php in your themeTheme A collection of files that determine a site's design, ... More folder with the templateTemplate A file in a theme that defines how different parts ... More headerThe top section of a website, usually containing the logo, n... More.
Step 2: Add your custom markup, loops, and WordPress functions:
php
<?php
/**
* Template Name: About Us
*/
get_header();
?>
<main id="primary" class="site-main">
<div class="container">
<header class="page-header">
<h1 class="page-title"><?php the_title(); ?></h1>
</header>
<div class="page-content">
<?php the_content(); ?>
<?php get_template_part('template-parts/team', 'members'); ?>
<?php get_template_part('template-parts/contact', 'cta'); ?>
</div>
</div>
</main>
<?php get_footer(); ?>Step 3: Create your templateTemplate A file in a theme that defines how different parts ... More parts.
template-parts/team-members.php:
php
<div class="team-section">
<h2>Meet Our Team</h2>
<div class="team-grid">
<?php
$team_members = new WP_Query(array(
'post_type' => 'team',
'posts_per_page' => -1,
'orderby' => 'menu_order'
));
if ($team_members->have_posts()) :
while ($team_members->have_posts()) : $team_members->the_post();
?>
<div class="team-card">
<?php if (has_post_thumbnail()) : ?>
<div class="team-photo">
<?php the_post_thumbnail('medium'); ?>
</div>
<?php endif; ?>
<h3><?php the_title(); ?></h3>
<p class="team-position"><?php echo get_post_meta(get_the_ID(), 'position', true); ?></p>
<?php the_excerpt(); ?>
</div>
<?php endwhile;
wp_reset_postdata();
endif;
?>
</div>
</div>Step 4: Create the pageStatic content (e.g., "About Us," "Contact") not part of chr... More in WordPress adminThe admin (administrator) is the highest user role with full... More, assign the “About Us” templateTemplate A file in a theme that defines how different parts ... More, and publish.
Now your about pageStatic content (e.g., "About Us," "Contact") not part of chr... More has a custom design, pulls content from the databaseWhere all WordPress content, settings, and user data are sto... More, includes reusable components, and integrates fully with WordPress. All without a single direct link to a PHP file.
wp-content/themes/yourtheme/file.php. It bypasses WordPress entirely.href="http://yoursite.com/about-us". Use echo site_url('/about-us/'); instead.Template Name: About Us in the file, it won’t appear in the adminThe admin (administrator) is the highest user role with full... More dropdown.the_content(): If your templateTemplate A file in a theme that defines how different parts ... More doesn’t include the_content(), the pageStatic content (e.g., "About Us," "Contact") not part of chr... More content you wrote in the editorA user role allowed to create, edit, publish, and delete pos... More will never display.get_template_part(): The function expects a slugThe URL-friendly version of a post/page title (e.g., my-awes... More, not a full path. get_template_part('content', 'featured') looks for content-featured.php, not content/featured.php.WordPress is a system, not a collection of static files. Once you embrace that, everything becomes simpler. Create pageStatic content (e.g., "About Us," "Contact") not part of chr... More templates with proper headers. Use get_template_part() for reusable components. Generate URLs dynamically with WordPress functions. Your code becomes cleaner, your sites become more maintainable, and you stop fighting the platform.
The old static HTMLHTML (HyperText Markup Language) The standard markup languag... More mindset served you well. But to build truly powerful WordPress sites, you need to work with the architecture, not around it. Start with one templateTemplate A file in a theme that defines how different parts ... More, build it correctly, and watch how the rest falls into place.