admin管理员组文章数量:1122832
Can I use the following function twice?
<php get_header(); ?>
<php get_header(); ?>
<div class="news-heading">
<span>Trending</span>
</div>
<?php get_footer(); ?>
Please share the logic behind it..
Can I use the following function twice?
<php get_header(); ?>
<php get_header(); ?>
<div class="news-heading">
<span>Trending</span>
</div>
<?php get_footer(); ?>
Please share the logic behind it..
Share Improve this question edited Oct 16, 2024 at 10:15 Rup 4,3904 gold badges28 silver badges29 bronze badges asked Oct 16, 2024 at 6:48 Ashutosh Kumar Singh RajbharAshutosh Kumar Singh Rajbhar 11 bronze badge1 Answer
Reset to default 2No, because get_header() calls locate_template() with load_once = true, meaning the actual template PHP is included with require_once
if ( $load_once ) {
require_once $_template_file;
} else {
require $_template_file;
}
so the second time you call it it won't load anything, as it's already loaded the same file before.
This makes sense for header because typically header includes the the html, head and body tags to set up the page - you wouldn't want to include it twice. Documentation here.
(If you meant is it safe to accidentally call get_header() twice then yes it is, the second call won't do anything. But you shouldn't be calling it twice no.)
If you have a separate block that you do want to include twice you can use get_template_part()
.
本文标签: theme developmentWordPress function getheader()
版权声明:本文标题:theme development - WordPress function::: get_header(); 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736281022a1926185.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论