Created
March 26, 2025 19:53
-
-
Save pattonwebz/9df75248004565ce65ab7f4bba49ce77 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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