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

Added support for attachment image html markup #517

Closed
wants to merge 4 commits into from

Conversation

maheshwaghmare
Copy link

Summary

After enabling the SVG image support when we use the function wp_get_attachment_image() used as:

$html = wp_get_attachment_image( $image_id, $size );

Then the HTML is generated as:

<img width="150" height="150" src="http://example.com/wp-content/uploads/2022/09/dummy-150x150.jpg" class="alignright not-transparent" alt="" loading="lazy" data-has-transparency="false" data-dominant-color="a26fd1" style="--dominant-color: #a26fd1;">

It keep serve the .jpg image version instead of .webp

This PR add the support with filter wp_get_attachment_image same as added support for post_thumbnail_html.

After adding the support the HTML markup generated as:

<img width="150" height="150" src="http://example.com/wp-content/uploads/2022/09/dummy-150x150-jpg.webp" class="alignright not-transparent" alt="" loading="lazy" data-has-transparency="false" data-dominant-color="a26fd1" style="--dominant-color: #a26fd1;">

Relevant technical choices

Checklist

  • PR has either [Focus] or Infrastructure label.
  • PR has a [Type] label.
  • PR has a milestone or the no milestone label.

@mukeshpanchal27 mukeshpanchal27 added [Focus] Images Issues related to the Images focus area [Type] Enhancement A suggestion for improvement of an existing feature no milestone PRs that do not have a defined milestone for release labels Sep 8, 2022
Copy link
Member

@mukeshpanchal27 mukeshpanchal27 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@maheshwaghmare Thanks for the PR. Can you please correct the unit tests?

@felixarntz I think it's good to update the markup for wp_get_attachment_image. Please share your thoughts on this.

modules/images/webp-uploads/load.php Show resolved Hide resolved
modules/images/webp-uploads/load.php Outdated Show resolved Hide resolved
maheshwaghmare and others added 3 commits September 12, 2022 19:15
Co-authored-by: Mukesh Panchal <mukeshpanchal27@users.noreply.github.com>
Co-authored-by: Mukesh Panchal <mukeshpanchal27@users.noreply.github.com>
Copy link
Member

@felixarntz felixarntz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@maheshwaghmare Thank you for the PR and for contributing to the performance plugin.

Unfortunately, at this point making this change is a bit preliminary and goes beyond what the current plan of the WebP module is, which is to automatically modify in-content images. Images retrieved via wp_get_attachment_image() are controlled by code (e.g. in a theme), and for now it was decided to leave control about that to the theme owner. For example, @jjgrainger has already been working on a core PR WordPress/wordpress-develop#3074 for this (which is closed for now, since this infrastructure will currently not proceed).

I think it's great you are raising this problem again in this PR though, and I agree we should think through it again, so I opened #523 for this purpose. Let's discuss there first whether that makes sense and what the potential complications are, before potentially proceeding with this PR.

Only marking this as requesting changes for now to first have this conversation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Focus] Images Issues related to the Images focus area no milestone PRs that do not have a defined milestone for release [Type] Enhancement A suggestion for improvement of an existing feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants