
Example of Anatomy of a WordPress Theme
<?php
/**
* Template Name: Custom Page Template
*
* This is a custom template file for a specific page in WordPress.
* You can use this template by assigning it to a page in the WordPress admin.
*/
// Retrieve the header
get_header();
?>
<div id="content" class="site-content">
<div id="primary" class="content-area">
<main id="main" class="site-main" role="main">
<?php
// Start the loop
while (have_posts()) :
the_post();
// Display the page content
the_content();
endwhile;
?>
</main><!-- #main -->
</div><!-- #primary -->
</div><!-- #content -->
<?php
// Retrieve the footer
get_footer();
?>
Here’s an explanation of each part:
/**
* Template Name: Custom Page Template
*
* This is a custom template file for a specific page in WordPress.
* You can use this template by assigning it to a page in the WordPress admin.
*/
This section is a comment block that provides information about the template. It specifies the template’s name as “Custom Page Template” and explains its purpose. It also instructs how to assign this template to a specific page in the WordPress admin area.
// Retrieve the header
get_header();
This line calls the get_header()
function, which retrieves the header template of your WordPress theme and includes it in the current page. It typically contains the HTML markup for the header section.
<div id="content" class="site-content">
<div id="primary" class="content-area">
<main id="main" class="site-main" role="main">
These lines define the main content area of the page using HTML <div>
elements with specific IDs and classes. It creates a container for the content and assigns the role
attribute for accessibility purposes.
<?php
// Start the loop
while (have_posts()) :
the_post();
// Display the page content
the_content();
endwhile;
?>
This section starts a loop that iterates through the posts. In this case, since it’s a custom page template, there should be only one post. The while
loop checks if there are more posts, and if so, it calls the the_post()
function to set up the post data.
Inside the loop, the the_content()
function is used to display the content of the page. This includes any text, images, or other elements added to the page editor in the WordPress admin.
</main><!-- #main -->
</div><!-- #primary -->
</div><!-- #content -->
These lines close the main content area <div>
tags that were opened earlier, ensuring proper HTML structure.
<?php
// Retrieve the footer
get_footer();
?>
Finally, this code calls the get_footer()
function, which retrieves the footer template of your WordPress theme and includes it in the current page. It typically contains the HTML markup for the footer section.

kumar
The Managing Director oversees the overall operations and strategic direction of the organization.
Category
- .NET (3)
- Blog (2)
- Common Technology (1)
- CSS (1)
- Topics (1)
- HTML (4)
- Basic HTML (4)
- Javascript (1)
- Topics (1)
- Laravel (32)
- Php (153)
- PHP Arrays (9)
- Php Basic (1)
- PHP interview (152)
- PHP Strings (12)
- Python (15)
- Python interview (13)
- React.js (32)
- React Js Project (3)
- Uncategorized (118)
- WordPress (114)
- Custom Post Types (7)
- Plugin Development (12)
- Theme Customizer (3)
- Theme Development (1)
- Troubleshooting (9)
- WordPress Customization (13)
- Wordpress Database (10)
- WordPress Example (5)
- WordPress Multisite (9)
- Wordpress Project (3)
- WordPress REST API (14)
- WordPress SEO (10)
Recent Posts
Tags
