How to create custom php script page

If you want to add custom page in WordPress, you need to add your custom PHP file into currently activated theme ( /wp-content/themes/ ) folder.

Suppose you have child-theme. Put the file to child-theme folder. Then goto page section, Click Add New.

In Page Attributes, Choose Template as your PHP File.

Open the Page.php file, It’s available from the theme folder. Copy the all thing except header and paste it into your PHP file. Your PHP file must need following codes.

<?php /* Template Name: CustomPageT1 */ ?>

<?php get_header(); ?>

<div id="primary" class="content-area">
    <main id="main" class="site-main" role="main">
        <?php
        // Start the loop.
        while ( have_posts() ) : the_post();

            // Include the page content template.
            get_template_part( 'template-parts/content', 'page' );

            // If comments are open or we have at least one comment, load up the comment template.
            if ( comments_open() || get_comments_number() ) {
                comments_template();
            }

            // End of the loop.
        endwhile;
        ?>

    </main><!-- .site-main -->

    <?php get_sidebar( 'content-bottom' ); ?>

</div><!-- .content-area -->

<?php get_sidebar(); ?>
<?php get_footer(); ?>

Leave a Comment