How to Display the Post Category as a Related Posts Title?

How to Display the Post Category as a Related Posts Title?

The Astra Theme comes with the Related Posts feature, which helps you engage your visitors for a longer time. This feature displays posts within the related category, suggesting that your visitors read more content related to their topic of interest. 

Astra Related Posts

Further, you might want to change the Related Posts section title and show the Post Category name instead. You can do this by adding a custom code (filter). 

To do this, you would need to add the following filter to the functions.php file of your Child Theme:

add_filter( 'astra_related_posts_title', 'astra_related_poat_title' );
function astra_related_poat_title() {
   return sprintf(
	'<div class="ast-related-posts-title-section"> <%1$s class="ast-related-posts-title"> %2$s </%1$s> </div>',
	'h2',// enter your custom string here
	esc_html__( get_the_category()[0]->name, 'astra' )
   );
}

Once the filter is added, the Related Posts section title will display the category name of the current post:

Filter to Display the Post Category as a Related Posts Title

If you don’t have your Child Theme installed, please check this article on how to do it.

If you are not sure how to add this code, please check this article

Was this doc helpful?
What went wrong?

We don't respond to the article feedback, we use it to improve our support content.

On this page

Take the First Step Toward Success Now.

You’re backed by an amazing team and a risk-free money-back guarantee!

Download is Just A Click Away!

Enter your email address and be the first to learn about updates and new features.

This field is required.

REWIND

YEAR IN REVIEW

Scroll to Top
Now choose your preferred
page builder addon
Choose your preferred page builder addon

Download is Just A Click Away!

Enter your email address and be the first to learn about updates and new features.

Download Free Astra Theme - Modal Popup Form