How to change the H2 in the header of the related entries of the Astra theme

astra theme templates

One of the free tools that incorporates the Astra theme are the related posts, available from the customizer, without having to install any plugin to have this functionality that improves the SEO of your website.

Now, despite the many settings you can configure, such as the type of query that will be made to display related entries and define its appearance in virtually all its elements, what does not exist is the ability to change the HTML tag with which the header is displayed, which uses a H2 by default.

And what do you want me to tell you, an H2 is too high a hierarchy of SEO headings, at the same level as that of the sections of an entry, more for a text that is going to be repeated in each entry.

It would be more appropriate to use something less hierarchical, like just a paragraph.

Well, it has an easy solution, you just have to add a function that modifies it, this one:

// Change H2 of related posts to h4 add_filter( 'astra_related_posts_title', 'update_related_posts_title_markup', 10, 1 ); function update_related_posts_title_markup( $markup ) { $markup = '<div class="ast-related-posts-title-section">'; $markup .= '<p class="ast-related-posts-title">'; $markup .= 'Entradas relacionadas'; $markup .= '</p>'; $markup .= '</div>'; return $markup; }
Code language: PHP (php)

Add this code to the end of the functions.php file of the Astra child theme, save the changes and you’re done.

Now you will see the header of the posts related to the text defined in the code, but without having the H2 tag, without having any weight in the SEO of the website.

Click to rate this post!
[Total: 0 Average: 0]

Leave a Comment

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

Scroll to Top Skip to content