Marketing Blog AZ

How to add h1 tag in wordpress​ (homepage​ , post...)

Published: Updated: Author:
Contents

Adding an H1 tag to a WordPress homepage makes it easier to optimize the homepage SEO for websites built with WordPress core. In this article, I’ll show you how to add an H1 tag in WordPress when any type of page is missing this tag.

How to add h1 tag in wordpress
The easiest way to add an H1 tag in WordPress

Add an H1 Tag to the WordPress Homepage

Are you looking for a way to add only one H1 tag to your WordPress homepage? I’ll show you how to insert a quick and simple code snippet to add an H1 page title to your blog or website homepage.

Please use only one of the two code snippets below to add an H1 tag to your WordPress homepage.

add_action( 'wp_body_open', function() {
    if ( ! is_home() ) {
        return;
    }
    ?>
        <div id="tagh1"><h1>Marketing blog AZ</h1></div>
    <?php
} );

Another way to do this is to open the header.php file and add the code just below the tag.

<?php if( is_home() || is_front_page() ) : ?>
  <div id="tagh1"><h1>>Marketing blog AZ</h1></div>
<?php endif; ?>

Simply hide the H1 tag with CSS if you only want to hide it on your homepage.

#tagh1 {
    display: none;
}

Put an H1 Tag in Your Blog Posts

Adding H1 Tags to Your WordPress Blog Posts is Super Simple to Do!

In WordPress, you can use just about any edit feature (Classic Visual Editor, TinyMCE, Gutenberg, Elementor Page Builder, etc) to mark a line or paragraph of text as an H1 Tag.

For example, if you want to Mark the title of your blog post as an H1 Tag, highlight the line of text that you wish to mark, and then click the Change block type or style icon as illustrated here.

Change block type or style icon Put an H1 Tag in Your Blog Posts

Changing Blog Post Title from H2 to H1: If you would like to make your WordPress Theme More SEO Friendly by converting from H2 Tags to H1, it is a Little More Complicated than Just Adding H1 Tags, as the Coding for each Theme Will Be Different (although Most Premium Themes will have a Small Code Snippet available That Will Allow You to Quickly and Easily Change Between These Heading Types.)

WordPress Automatically Append H1 Tags to Categories and Tags

It’s easy to add an H1 tag automatically to your WordPress Category or Tag Page when the Page title is used as the H1 tag.

In order to do this you simply have to add some code to your functions.php file.

function hidden_term_name_action() {

    if( is_category() || is_tag() ){

        $term_id = get_queried_object_id();
        $term = get_term($term_id);
        if($term){
            echo sprintf('<h1 style="display:none;">%s</h1>', esc_attr($term->name));
        }
    }

}

add_action('hidden_term_name', 'hidden_term_name_action');

You need to additionally add the following code in your header.php file in your WordPress Theme Directory.

<?php do_action('hidden_term_name'); ?>

Using this method will create an H1 Tag on all of your Category and Tag Archive Pages, making it easier for Search Engine Bots to read and comprehend the Page Structure.

There are many methods available to add H1 Tags in WordPress such as Post Pages, Homepages, Category Pages and etc. As much as possible, choose the easiest and most effective way to save time and avoid doing redundant work on multiple files.

If you plan on changing the H1 Tag via your Theme files, be sure to create a Child Theme and copy those files into the Child Theme before making any changes. This way you ensure your Custom Code does not get deleted or lose functionality when your Main Theme generates updates.

Code reference source: Stack Exchange.

Share

Share this blog
Alex Min

Author

Alex Min

WAlex Min is a Digital Marketing specialist with strengths in website development, sales advertising campaigns, and online growth strategy. I am currently working as a marketing specialist for a B2B company in the industrial sector, focusing on improving communication effectiveness with factories, attracting potential customers, and supporting sales growth.

Keep reading

Related Posts