Closed. This question is off-topic. It is not currently accepting answers.admin管理员组文章数量:1278793
Your question should be specific to WordPress. Generic PHP/JS/SQL/HTML/CSS questions might be better asked at Stack Overflow or another appropriate Stack Exchange network site. Third-party plugins and themes are off-topic for this site; they are better asked about at their developers' support routes.
Closed 3 years ago.
Improve this questionFirst 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.
Closed. This question is off-topic. It is not currently accepting answers.Your question should be specific to WordPress. Generic PHP/JS/SQL/HTML/CSS questions might be better asked at Stack Overflow or another appropriate Stack Exchange network site. Third-party plugins and themes are off-topic for this site; they are better asked about at their developers' support routes.
Closed 3 years ago.
Improve this questionFirst 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.
Share Improve this question asked Oct 9, 2021 at 23:52 perezperez 31 bronze badge 1 |1 Answer
Reset to default 0I guess the problem relies on the header.php
file. head
tag doesn't support a div
or img
. However, browsers like Chrome autocorrect the issue by moving the div
from head
to body
.
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>
get_template_directory_uri()
will return the URI to current theme's template directory. So if you put the image within the img
directory of the active
theme, the image will load on all the pages.
本文标签: phpHeader is not displaying on certain pages of wordpress theme
版权声明:本文标题:php - Header is not displaying on certain pages of wordpress theme 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741278837a2369890.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
div
andimg
tags inside yourhead
tag, that's not valid HTML. It also uses a hardcoded relative URL so the location it looks in is different on every page which is probably not what you wanted. I don't think any of your issues are WordPress but rather fundamental HTML problems – Tom J Nowell ♦ Commented Oct 10, 2021 at 0:56