Topic: Edit image inside tags? (img attribute values)
Hello, I use htmLawed on WordPress posts and works great.
include_once ( TEMPLATEPATH . '/htmLawed.php' ); //
function clean_the_content( $content )
{
$szPostContent = $content;
$szRemoveFilter = array( "~<font[^>]*>~", "~</font>~", "~<div[^>]*>~", "~</div>~", "~<span[^>]*>~", "~</span>~", "~<table[^>]*>~", "~</table>~", "~<script[^>]*>~", "~</script>~", "~<SCRIPT[^>]*>~", "~</SCRIPT>~");
$szPostContent = preg_replace( $szRemoveFilter, '' , $szPostContent);
$szPostContent = htmLawed($szPostContent);
return $szPostContent;
}
add_filter('the_content', 'clean_the_content');
My main problem is that I need to edit inside image tag, is that possible?
For example: this is by default:
<img class="aligncenter size-full wp-image-33089" src="https://www.domain.com/image1.jpg?w=474&h=474" alt="" width="474" height="474" />
And I need it to be:
<img class="aligncenter" src="https://www.domain.com/image1.jpg" width="100%" />
So my question is, can I add custom function or something that it would change the class, width and if possible remove everything after jpg questionmark (.jpg?w=...)
If it is possible, how to apply it to clean_the_content function?