WordPress Dev: How to code and add a custom page to your theme

Post author: Adam VanBuskirk
Adam VanBuskirk
5/13/23 in

Here are the steps to add a custom page to WordPress using a custom page template:

  1. Create a new PHP file in your theme directory with a name that indicates that it is a page template (e.g. custom-page-template.php).
  2. At the top of the file, add the following comment block to indicate that this is a page template:
 * 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>

<?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.

Sign up today for our weekly newsletter about AI, SEO, and Entrepreneurship

Leave a Reply

Your email address will not be published. Required fields are marked *

Read Next

© 2024 Menyu LLC