How to Change the Heading Tag for the Page/Post Titles?

From Astra Settings ( Edit Page / Edit Post > Astra Settings > Disable Sections > Disable Title ), you can enable or disable the Page/Post Title for the site. A Page/Post title is usually used to let the user know on which page he is currently on.

Are you looking to change the tag of Title – Like Page/Post title. You can use the below filters to change the Tag of the Titles.

By default this Title has heading tag <h1> in HTML structure. You can change this tag to any other HTML tag using the following filter

add_action( 'wp', 'astra_add_title_filter' );

/**
* Function to add filters to change titles.
*
* @return void
*/
function astra_add_title_filter() {
	add_filter( 'astra_the_title_before', 'astra_the_title_before_tag', 1, 10 );
	add_filter( 'astra_the_title_after', 'astra_the_title_after_tag', 1, 10 );
}

/**
* Function to change tag in all titles.
*
* @param string $tag This contains default tag used for the titles.
* @return string
*/
function astra_the_title_before_tag( $tag ) {
	$tag = '<h4>';
	return $tag;
}

/**
* Function to change tag in all titles.
*
* @param string $tag This contains default tag used for the titles.
* @return string
*/
function astra_the_title_after_tag( $tag ) {
	$tag = '</h4>';
	return $tag;
}

Note:
1. Above filter will change <h1> tag to <h4> tag. You can update it as per your requirement.
2. Paste the above code in the child theme’s functions.php file.

Note: The following functions astra_the_title_before_tag and astra_the_title_after_tag will contain the same heading tag as one is for the opening tag and the other one is for the closing tag, Just like we have used <h4> and </h4>

Default Tag

Heading Tag after adding the Filter

Not the solution you are looking for? Check other articles, or open a support ticket.