Created
June 15, 2012 13:22
-
-
Save jdevalk/2936443 to your computer and use it in GitHub Desktop.
If title attribute == alt attribute, strip title attribute.
This file contains 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 | |
if ( preg_match_all( '/<img [^>]+>/', $post->post_content, $matches ) ) { | |
$content_changed = false; | |
foreach ( $matches[0] as $img ) { | |
preg_match( '/title=("|\')([^"\']+)("|\') /', $img, $title_match ); | |
preg_match( '/alt=("|\')([^"\']+)("|\') /', $img, $alt_match ); | |
if ( isset($title_match[2]) && isset($alt_match[2]) && $title_match[2] == $alt_match[2] ) { | |
$post->post_content = str_replace( $title_match[0], '', $post->post_content ); | |
$content_changed = true; | |
} | |
} | |
if ( $content_changed ) { | |
wp_update_post( $post ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment