Sign up ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm trying to get rid of the non W3C compliant "align" attribute generated with any images.

For that, I'm using the simple_html_dom library. Here's the code i'm using :

add_filter( 'post_thumbnail_html', 'clean_image_attributes', 10 );
add_filter( 'image_send_to_editor', 'clean_image_attributes', 10 );
add_filter( 'the_content', 'clean_image_attributes', 10 );

function clean_image_attributes($html)
    $output = new simple_html_dom();

    foreach ($output->find("img") as $img)
        if (isset($img->align))
            $img->align = null;
            $img->class .= ' clearfix';

    $html = $output->save();
    return $html;

What the function does is just looking if the image has the align attribute and remove it. This works pretty well, except that when I call the_content(), the layout of my post is kinda broken, the

got removed but I have no idea why...

share|improve this question
Part of your question got cut off by formatting. What part got removed? (I see "the [something's missing here] got removed..."). –  morganestes Aug 19 '13 at 15:48
Can you tell me your site link so that i can debug it? –  Vinod Dalvi Aug 19 '13 at 17:32
Sorry, all my paragraphs tags got removed. Here's a link : As you can see for example on the first post, all the text goes on 1 line, but there should be 3 2 paragraphs instead –  user510990 Aug 19 '13 at 18:10

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.