• I would really like some help in doing this, I’ve tried googling with little success. I would really like to disable the automatic adding of the height and width attributes on images in WordPress.

    Is anyone able to give me some pointers on this?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Hi,

    You need to remove the image style sheet from the style.css file of your theme..once you remove it automatic/default settings of the image will not be work.

    Thanks,

    Shane G.

    Thread Starter mellow_bunny

    (@mellow_bunny)

    Ok maybe I should be a little more specific. WordPress automatically adds the width and height attributes to all <img> tags I insert into a post or page.

    <img class="alignnone size-full wp-image-24" title="CoolWhip" src="http://mellowspace.com/wp-content/uploads/2009/08/CoolWhip.png" alt="CoolWhip" width="1920" height="1080" />

    I want to stop it from entering in those attributes. I’m not sure that removing img styling from my CSS will have any effect.

    Edit: Whenever you insert an image it asks you to select a size, giving options of Thumbnail, Medium, Large and Full Size. I would love to be able to choose a fifth option “Not set”. This would I assume prevent WordPress from adding the width & height attribute if it was defined correctly.

    Thread Starter mellow_bunny

    (@mellow_bunny)

    So I have been able to do this by altering the get_image_tag function inside /wp-includes/media.php. I altered just one line from this:

    $html = '<img src="' . esc_attr($img_src) . '" alt="' . esc_attr($alt) . '" title="' . esc_attr($title).'" '.$hwstring.'class="'.$class.'" />';

    Into this:

    $html = '<img src="' . esc_attr($img_src) . '" alt="' . esc_attr($alt) . '" title="' . esc_attr($title).'" class="'.$class.'" />';

    The only variable removed was $hwstring. I was hoping to override this function but it’s not in pluggable.php of course.

    So for now I’ll make use of this hack but I think I will create a plugin to remove the attributes with regex using a filter or action hook or something. That would be a better longterm solution. All that would be required is for the plugin to find the attributes and remove them before saving the post to the database.

    Did you ever make that plugin?
    I was trying a different approach here:
    http://wordpress.org/support/topic/368457?replies=1

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Disabling automatic height and width on <img> tags.’ is closed to new replies.