Search for h1 tags in the_content() and change to e.g. h2

In relation to this post which deals with remove the h-1 option in WordPress text editor Drowdown it might be an idea to make a search and replace in the_content() which then changes all h1 tags to another, e.g. an h2.

Why is it a good idea to remove duplicate h1 tags?

Because it is recommended to have only one h1 tag per page. For these reasons, it may be a solution to simply change all h1 tags via a function that therefore solves the problem of too many h1 tags. The idea of this function is to help an author who has no prior knowledge of HTML to create headings and structure his content appropriately.

Use this function in your functions.php file. It searches for h1 tags and changes them to h2.


function get_content_without_h1(){
	$str = wpautop( get_the_content() );
	$str = str_replace('h1', 'h2', $str);
	return apply_filters( 'the_content', $str );
}