php – Header is not displaying on certain pages of wordpress theme

Question

First time making a wordpress theme. I can’t seem to get my header to display on certain pages (archive.php). It displays perfectly fine on my front page, etc. Just not in the archive or individual posts. My code is below…

archive.php

<?php get_header();?>
<div class="container">

<h1><?php single_cat_title();?></h1>

<?php if (have_posts()) : while(have_posts()) : the_post();?>


<div class="card mb-4">
    <div class="card-body">
    <?php if (has_post_thumbnail()):?>

<img src="<?php the_post_thumbnail_url('smallest');?>" class="img-fluid">

<?php endif;?>
    <h3><?php the_title();?></h3>
    <?php the_excerpt();?>
    <a href="<?php the_permalink();?>" class="btn btn-success">Read more</a>
    </div>
    </div>
<?php endwhile; endif;?>

</div>
<?php get_footer();?>

front-page.php

<?php get_header();?>
<div class="container">

<h1><?php the_title();?></h1>

<?php if (have_posts()) : while(have_posts()) : the_post();?>

    <?php the_content();?>

<?php endwhile; endif;?>

</div>
<?php get_footer();?>

header.php

<!DOCTYPE html>
<html <?php language_attributes(); ?>>
   
    <head>
            <?php wp_head(); ?>
            <div class="logo">
    <img class="logo" src="img/pmflogolandscapedemo_crop.png" width="100%" alt="">
</div>
    </head>

<body <?php body_class(); ?>>
    



<header>

<div class="container">
    <?php wp_nav_menu (

        array(

            'theme_location' => 'top-menu',
            'menu_class' => 'navigation'

        )

    );
    ?>
</div>

</header>

Is there a different file in the theme that might be causing this? I can’t seem to spot any issues between this page and other ones like my front-page.php, where the header displays fine.

Thanks in advance for any assistance, I’m really struggling with the basics here.

in progress 0
perez 2 months 2021-10-09T18:52:07-05:00 0 Answer 0 views 0

Answer ( 1 )

    0
    2021-10-12T13:50:58-05:00

    The header logo is working on the front-page because you set a relative path for the logo. So when you are on the homepage, the logo URL becomes yoursite.tld/img/pmflogolandscapedemo_crop.png. Maybe the logo exists there. But when you visit an archive page, the logo URL becomes yoursite.tld/{archive-url}/img/pmflogolandscapedemo_crop.png where the image doesn’t exist.

    On the header.php file, you may try this.

    <!DOCTYPE html>
    <html <?php language_attributes(); ?>>
        <head>
                <?php wp_head(); ?>
        </head>
    <body <?php body_class(); ?>>
    <header>
    <div class="logo">
        <img class="logo" src="<?php echo get_template_directory_uri(); ?>/img/pmflogolandscapedemo_crop.png" width="100%" alt="">
    </div>
    <div class="container">
        <?php
        wp_nav_menu(
            array(
    
                'theme_location' => 'top-menu',
                'menu_class'     => 'navigation',
    
            )
        );
        ?>
    </div>
    
    </header>
    

Leave an answer

Browse
Browse