skip to Main Content

WordPress post titles are usually in the h1 tag by default. How to write the post title inside the h2 tag?
WordPress Post Title

I go through all the themes files but can not get any solution. When I Inspect the page, I find this A Comprehensive Guide to Holistic Health and Wholeness. Which means the page title is inside the named "entry-title". But I can not find such a class in the theme files. I need to modify the title tag and make it into h2 tag. Squaretype theme is used here.

2

Answers


  1. You can render the H2 tag for title by passing parameters in the_title() function, like this:-

    <?php the_title('<h2>','</h2>'); ?>
    

    This is written in the user contribution in the_title() function page of WordPress documentation. I read it there.

    Another way is to use get_the_title() function, it will just give the title text. And then you can wrap it in the h2 element. Here is the example:-

    <h2><?php echo get_the_title(); ?></h2>
    
    Login or Signup to reply.
  2. Here you can find the post title in single.php file or content-single.php file just replace

    <?php the_title( '<h2 class="entry-title">', '</h2>' ); ?>
    or
    <h2><?php echo get_the_title(); ?></h2>
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search