Archived topic
HTML tag of main title
1 reply · Started by Adrian on February 5, 2017
Hi Tom,
on my website I want to use the H1 tag for the main title when the front page is shown, and the P tag when another page is shown. For SEO reasons.
I created a child theme to accomplish the same, but then came across the following code, from which I see your theme already has this feature built in:
file: /inc/template_tags.php
<?php if ( is_front_page() && is_home() ) : ?>
<h1 class="main-title" itemprop="headline">" rel="home"><?php bloginfo( 'name' ); ?></h1>
<?php else : ?>
<p class="main-title" itemprop="headline">" rel="home"><?php bloginfo( 'name' ); ?></p>
<?php endif; ?>
Strangely enough, on my website the P tag is used on the front page as well. I am using Generatepress in its normal configuration, with the site title shown in the header.
So is_front_page() is true, but why do you check is_home()? It applies to blogs only, if I understand the documentation correctly.
Once I remove is_home() the functionality works as desired.
Thanks Tom
Adrian
This is because regular pages already have an H1, your page title.
The blog (is_home()) doesn't have a page title, so we use the site title.
If you're using a static front page, then you should already have an H1, and don't need/shouldn't have your site title as an H1.
Let me know if you need more info :)