WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] How to remove hard coded dimensions from post gallery images? (5 posts)

  1. joaoramos
    Member
    Posted 2 years ago #

    How can I insert pictures into a post without any hard coded dimensions (e.g. <img src="" alt=""/ > instead of <img src="" alt="" width="" height="" />)? I'm using this snippet, but it doesn't seem to work properly with images pulled via wp_get_attachment_image();:

    `function remove_img_src($html) {
        $html = preg_replace('@(width|height)="([0-9])+" ?@i', '', $html);
        return $html;
    }
    
    add_filter('image_send_to_editor', 'remove_img_src', 10, 8);
    `
    Any ideas?
  2. seanjacob
    Member
    Posted 2 years ago #

    You could do it with jQuery but I don't know if that would be the right way...

    $(.class img).removeAttr('height').removeAttr('width');

  3. joaoramos
    Member
    Posted 2 years ago #

    Thanks, but I'd prefer doing it on the server side. Any ideas?

  4. seanjacob
    Member
    Posted 2 years ago #

    How about just getting the src if you are not bothered about the alt tag?

    wp_get_attachment_image_src()

    http://codex.wordpress.org/Function_Reference/wp_get_attachment_image_src

  5. joaoramos
    Member
    Posted 2 years ago #

    It worked perfectly! Thanks!

Topic Closed

This topic has been closed to new replies.

About this Topic