1
votes

I know this question is already asked a lot, but every time I read an answer on those questions it looks like I've implemented it like I should've. My problem is as follows:

I have added the following statement to my index.php to load a different header (saved in header-frontpage.php) for my static home page (called page-home.php).

if(is_front_page())
{
    get_header('frontpage');
}
else 
{
    get_header();
}

I have also set page-home as my static front page in the wordpress settings->read.

Shouldn't this result in my homepage loading the header-frontpage.php? Now it just retreives my header.php for my frontpage as well. A live preview can be found at www.koencuijpers.com (wrong loading of header.php) and www.koencuijpers.com/spot-map (right loading of header.php).

My complete code for my index.php is:

<?php
/**
 * The main template file.
 *
 * This is the most generic template file in a WordPress theme
 * and one of the two required files for a theme (the other being style.css).
 * It is used to display a page when nothing more specific matches a query.
 * E.g., it puts together the home page when no home.php file exists.
 *
 * @link https://codex.wordpress.org/Template_Hierarchy
 *
 * @package Spot_Utrecht
 */

if(is_front_page())
{
    get_header('frontpage');
}
else 
{
    get_header();
}
 ?>

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

        <?php
        if ( have_posts() ) :

            if ( is_home() && ! is_front_page() ) : ?>
                <header>
                    <h1 class="page-title screen-reader-text"><?php single_post_title(); ?></h1>
                </header>

            <?php
            endif;

            /* Start the Loop */
            while ( have_posts() ) : the_post();

                /*
                 * Include the Post-Format-specific template for the content.
                 * If you want to override this in a child theme, then include a file
                 * called content-___.php (where ___ is the Post Format name) and that will be used instead.
                 */
                get_template_part( 'template-parts/content', get_post_format() );

            endwhile;

            the_posts_navigation();

        else :

            get_template_part( 'template-parts/content', 'none' );

        endif; ?>

        </main><!-- #main -->
    </div><!-- #primary -->

<?php
get_sidebar();
get_footer();
?>
1
This page has information that may help you suss it out (look halfway down for a thorough discussion of the differences between is_home and front_page: codex.wordpress.org/Function_Reference/is_homevlasits

1 Answers

1
votes

If you've set your homepage as a static page, then WordPress will be following its template hierarchy to decide what template to use:

https://developer.wordpress.org/themes/basics/template-hierarchy/#front-page-display

This means WordPress will not be using index.php as the template for your front page, so whatever changes you make there will have no effect.

Therefore you need to include your if statement in the appropriate template (probably front-page.php, depending on your theme setup).