Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong image size set when using wp_get_attachment_image() (fix) #54

Open
EmilEriksen opened this issue Dec 20, 2014 · 2 comments
Open

Comments

@EmilEriksen
Copy link

When using this function the image won't be returned with a size-$size class but with an attachment-$size class and thus Picturefill.WP will set an incorrect size. This can easily be fixed though:

add_filter( 'picturefill_wp_initial_image_attributes', 'prefix_get_image_size_attribute' );
function prefix_get_image_size_attribute( $attributes ) {

    if ( empty( $attributes['size'] ) ) {
        if ( preg_match( '/(?:(?:^|\s)attachment-)([\w|-]+)/', $attributes['class'], $size_match ) ) {
            $attributes['size'] = $size_match[1];
        }
    }

    return $attributes;
}
tychay added a commit to tychay/picturefill.js.wp that referenced this issue Apr 24, 2015
@tychay
Copy link

tychay commented Apr 24, 2015

Nice catch.

Looks like WordPress core has a bug where get_image_tag() returns a different class than wp_get_attachment_image(). This shouldn't be a filter though, but patched in the plugin itself given the core spits it out.

Patch:
tychay@c8794c8

Note to upstream: Without this patch, post thumbnails won't get properly sized (not sure they'll get properly sized post patch as I don't use this plugin yet).

I submitted a bug report at https://core.trac.wordpress.org/ticket/32093 but I doubt it will be fixed at this point as post thumbnails have been with us for over three years.

tychay added a commit to tychay/picturefill.js.wp that referenced this issue Apr 24, 2015
@tychay
Copy link

tychay commented Apr 29, 2015

Pull request #64

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants