-
-
Save ramsesdelr/5b935d17caa47d0e3ee9d8c19f166bd2 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 | |
| /** | |
| * Based on the regex findings, we process their response and add the new class to the matching results. | |
| * | |
| * @param array $matches An array of matches. | |
| * @param string The processed content. | |
| */ | |
| function add_extra_strong_class( $matches ) { | |
| $tag = $matches[1]; | |
| $attributes = $matches[2]; | |
| // Check if any class attribute exists. | |
| if ( preg_match( '/\\bclass\\s*=\\s*["\\"]([^"\\"]*)["\\"]/', $attributes, $class_match ) ) { | |
| $classes = explode( ' ', $class_match[1] ); | |
| // Check if "extra-strong" class already exists. | |
| if ( ! in_array( 'extra-strong', $classes, true ) ) { | |
| $classes[] = 'extra-strong'; | |
| } | |
| $attributes = str_replace( $class_match[0], 'class="' . implode( ' ', $classes ) . '"', $attributes ); | |
| } else { | |
| // If no class attribute exists, add the entire class attribute. | |
| $attributes .= ' class="extra-strong"'; | |
| } | |
| return '<' . $tag . $attributes . '>'; | |
| } | |
| preg_replace_callback( '/<(b|strong)([^>]*)>/si', 'add_extra_strong_class', $post_content ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment