I’m trying to use wp_title()
to create a heading for my pages, but I’m using a static front page and, while all of the other pages render the title properly, the front page won’t.
This is what I’m working with:
<div id="main-content">
<h1><?php wp_title("", true); ?></h1>
<?php while( have_posts() ) : the_post() ?>
<div class="pagecontent">
<?php the_content(); ?>
</div>
<?php endwhile ?>
</div>
Initially I thought that the front page might be drawing from index.php
, so I added the same code snippet in there â but, no such luck, the same thing gets rendered â an empty h1
tag.
What’s going on here? I want the title of the page to show up in the h1 tag.
wp_title() is for the html title tags in your websites head section.
It’s not for outputting a title. Use the_title(), or get_the_title(),
If you look at the source of
wp_title()
you will see that there is not output planned for a static front page.Use
the_title()
for visual output as @Chris_O suggested. But for the title in the<head>
section you have to filterwp_title()
and fill it if it is empty.Sample code (download from GitHub):