Saturday , February 22 2025

How to display h1 in WordPress theme

This task is relevant for cases when developers in custom templates for some reason decide not to display the page title, although according to all SEO requirements it should be, and should be wrapped in h1.

Heading Examples

1. In the page template:

in the page.php of your theme, add the following construction:

<?php echo '<h1>'. esc_html( get_the_title() ) .'</h1>'; ?>

2. In the post template:

in the file single.php or content-single.php add the same code:

<?php echo '<h1>'. esc_html( get_the_title() ) .'</h1>'; ?>

3. In the categories template (post archives):

in the file archive.php add this code:

<?php the_archive_title( '<h1 class="page-title">', '</h1>' ); ?>

About iryna

I'm Iryna, a web developer from Ukraine with a decade of experience solving complex technical challenges in the world of freelance. Throughout my career, I've worked on everything from troubleshooting server-side issues and optimizing website performance to enhancing user interfaces. On this blog, I share detailed solutions to the technical problems I’ve encountered and methods that have worked best for me. In addition to my technical expertise, I’m also passionate about digital drawing. I hope the tutorials and insights I provide here will help both fellow developers and creatives alike in their own projects.

Check Also

How to remove 404 //fonts.gstatic.com and //fonts.googleapis.com from WordPress head section

I tried solutions with functions that should remove from head and , but a very …

Leave a Reply

Your email address will not be published. Required fields are marked *