How to make a page as default page for a theme without a plugin?


I am trying to make a page to be persistent as the home page for my custom theme. In which I can download from Github and setup the WordPress and this page appears as the default one. I created a page within the theme as front-page.php and added the following code within it:

/* Template Name: front-page */


<div id="primary" class="content-area">
        <main id="main" class="site-main">

        if ( have_posts() ) {

            // Load posts loop.
            while ( have_posts() ) {
                get_template_part( 'template-parts/content/content' );

            // Previous/next page navigation.

        } else {

            // If no content, include the "No posts found" template.
            get_template_part( 'template-parts/content/content', 'none' );


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


However, it just appears as normal template. The same as if I created a books.php page and setup it as the template name as well. I know it can be done from setthings>reading but I just would like to set it as the default one.

I have also added the following code into the functions.php to display the front-page.php template as the default but it makes the homepage disappear.

* Add custom template as default page

add_filter( 'template_include', 'breed', 99 );

function breed( $template ) {

    if ( is_singular( 'page' )  ) {
        $default_template = locate_template( array( 'breed.php' ) );
        if ( '' != $default_template ) {
            return $default_template ;

    return $template;
Elias Prado 1 month 0 Answers 8 views 0

Leave an answer