Insert H1 only in Homepage

How can i insert <h1> only in home page?

Hi @jlampreia,

Your website is not accessible right now:

Could you please double check?

Thank you.

Hi thai, thanks for reply.
I´ve checked and the website is online.

Hello Jlampreia,

Thanks for updating the thread.

I checked the website and it’s working fine. If you are looking to add H1 tags in homepage, please take a look at following tutorial.

Thanks.

Hi Prashant,
thanks in advance for the topic update.
I’ve applied the code snippet to the header.php but this will introduce the h1 text too.
Maybe i’ve didn’t explain well, i want to add the h1 only to the homepage but without h1 text in the site design.
Is this possible?

Att.
José Lampreia

Hello Jose,

Do you want to insert <h1></h1> tag with no text?

Please be informed that there is a setting in the theme options that automatically adds h1 to your site. Simply go to X > Theme Options > Header > Logo - Text and enable the "Output Logo Text in Hidden <h1>". This should display an <h1> which do not have any text or display in the front end of the page.

We would love to know if this has worked for you. Thank you.

Thanks RueNel,
i appreciatte your tip,
i know about that function, but if “output logo text in hidden h1”, this will be for all pages, i have h1 on the other pages, i need a custom hidden h1 only on homepage. Is this possible?

Att.
Jlampreia

Hey Jlampreia,

To add a custom hidden <h1> tag only on homepage, simply add the following code in your child theme’s functions.php file

add_action( 'x_before_the_content_begin', 'add_hidden_tag_on_homepage' );
function add_hidden_tag_on_homepage() {
if ( is_front_page() ) {	
	echo'<h1 class="hide">Only Displays On The Front Page</h1>';
    }
}

Hope this helps!

1 Like

Thank you Nabeel,
is working wonderfully, X Theme support is top.

On behalf of my colleague, you’re welcome. Cheers! :slight_smile:

Hi,
i have two languages in this website, PT / EN, so now the h1 is the same for both languages in homepage.
Is there a way that i can add a PT and EN language h1 to this home pages from functions.php file?

Hi There @jlampreia

If you’re using a plugin like WPML, you can target your languages as follows and add your code.

<?php if(ICL_LANGUAGE_CODE=='en'): ?>
  // Do something
<?php elseif(ICL_LANGUAGE_CODE=='it'): ?>
  // Do something
<?php endif; ?>

If you have setup separate WordPress sites on sub-folders for your other languages, you will need to setup a child theme for each WordPress site and add your code there.

Hope that helps.

Hi @mldarshana,
thank for your help.

I´m using the Polylang Plugin, and i´ve applied the code like this:

<?php if(ICL_LANGUAGE_CODE=='pt'): ?>
add_action( 'x_before_the_content_begin', 'add_hidden_tag_on_homepage' );
function add_hidden_tag_on_homepage() {
if ( is_front_page() ) {	
	echo'<h1 class="hide"></h1>';
    }
}
<?php elseif(ICL_LANGUAGE_CODE=='en'): ?>
add_action( 'x_before_the_content_begin', 'add_hidden_tag_on_homepage' );
function add_hidden_tag_on_homepage() {
if ( is_front_page() ) {	
	echo'<h1 class="hide"></h1>';
    }
}
<?php endif; ?>

But it´s not working,

Att.
jlampreia

Hi Jlampreia,

For the Polylang plugin, please try following this resource (https://gist.github.com/beovulf/5a1c26bec2eadd7bde413fc81df31771).

Hope that helps.

Hi @mldarshana,
thank you for the post update.
The theme breaks, i think i´m doing something wrong.
Maybe there´s a way with css to override the “en-GB” h1 in homepage?

Hi @jlampreia,

Can you clarify this The theme breaks, i think i´m doing something wrong.. Is it a fatal error or design error? Fatal error means after you have added the code, you can’t view the site. Design error means the site still loads but there’s error on layout. Can you share the exact code you have added?

Also, with this Maybe there´s a way with css to override the “en-GB” h1 in homepage? what exactly do you want to achieve?

Hi @Lely,
thank you for the post update.

Well yes is a fatal error, because when i added the code to functions.php child theme, i can´t view the site.

I want to achieve the following:

I´ve added to functions.php child theme the code provided by @Nabeel, but then i find out this will put the same h1 to PT and EN homepages, so i want to have a different h1 in each homepages.

Att.
José Lampreia

Hello Jose,

You will need to update your code and use this instead:

add_action( 'x_before_the_content_begin', 'add_hidden_tag_on_homepage' );
function add_hidden_tag_on_homepage() { ?>

	<?php if(ICL_LANGUAGE_CODE=='en'): ?>
		
		<?php if ( is_front_page() ) : ?>
			<h1 class="hide">Only Displays On The Front Page</h1>
	    <?php endif; ?>
		
	<?php elseif(ICL_LANGUAGE_CODE=='it'): ?>
		
		<?php if ( is_front_page() ) : ?>
			<h1 class="hide">Only Displays On The Front Page</h1>
	    <?php endif; ?>

	<?php endif; ?>

<?php }


We would love to know if this has worked for you. Thank you.

1 Like

Yes, Yes, Yes,
it is working perfect, thanks a lot @RueNel and all X Theme Support guys.

:heart: Xtheme :muscle:

You’re most welcome @jlampreia ! :slight_smile: