php - Wordpress - Retrieve IMG's from the_content and clean it -
i'm trying build function wordpress website, retrive img's the_content, , clean bunch of operations:
- removing class (you know, e.g. class="alignnone size-full wp-image-707")
- replacing alt post's title + number avoid duplicate alts
- indenting match clean-code-obssession
when echo the_content, call 'clean_image_set' function:
add_filter("the_content", "clean_image_set"); the_content();
the function looks this:
function clean_image_set($html) { $html = preg_replace( '/(class=")(.*?)(")/i', "class=\"img\"", $html ); $post_title = get_the_title(); $html = preg_replace( '/(alt=")(.*?)(")/i', '$1'.esc_attr( $post_title ).'$3', $html ); // replace alt post title return $html; }
i think should use preg_match_all put imgs array , use loop put number in alt , add indentation, can't manage it.
any thought? lot!
Comments
Post a Comment