Here are the steps to add a custom page to WordPress using a custom page template:
custom-page-template.php
).<?php
/**
* Template Name: Custom Page Template
*/
Replace “Custom Page Template” with the name you want to give your template.
3. Write the HTML and PHP code for your custom page within the body
tags of the template file. You can use WordPress functions to display content from your site, such as get_header()
and get_footer()
to include the site header and footer, respectively. Here’s an example:
<?php get_header(); ?>
<div id="primary" class="content-area">
<main id="main" class="site-main">
<h1>Welcome to my Custom Page</h1>
<p>This is some content for my custom page.</p>
</main>
</div>
<?php get_footer(); ?>
4. Save the file and upload it to your theme directory.
5. Create a new page in WordPress by going to Pages > Add New in the WordPress dashboard.
6. Give your page a title and then look for the “Page Attributes” box on the right-hand side of the editor.
7. In the “Template” dropdown, select the custom page template you just created.
8. Publish or update the page.
9. View your new custom page on the front end of your site by clicking the “View Page” link or by navigating to the URL of the page.
That’s it! Your new custom page should now be visible on your WordPress site using the custom page template you created.