Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save pattonwebz/9df75248004565ce65ab7f4bba49ce77 to your computer and use it in GitHub Desktop.

Select an option

Save pattonwebz/9df75248004565ce65ab7f4bba49ce77 to your computer and use it in GitHub Desktop.
<?php
/**
* Fix incorrect heading order in post content.
*
* @param string $content The post content.
* @return string Modified content with correct heading structure.
*/
function fix_heading_order_in_content( $content ) {
// Replace incorrect H2 with H3 (example scenario).
$content = preg_replace( '/<h2([^>]*)>(.*?)<\/h2>/', '<h3$1>$2</h3>', $content );
// Replace incorrect H4 with H2 (example scenario).
$content = preg_replace( '/<h4([^>]*)>(.*?)<\/h4>/', '<h2$1>$2</h2>', $content );
return $content;
}
add_filter( 'the_content', 'fix_heading_order_in_content' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment