Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Added support for attachment image html markup#517

Closed
maheshwaghmare wants to merge 4 commits into
WordPress:trunkfrom
maheshwaghmare:patch-1
Closed

Added support for attachment image html markup#517
maheshwaghmare wants to merge 4 commits into
WordPress:trunkfrom
maheshwaghmare:patch-1

Conversation

@maheshwaghmare

Copy link
Copy Markdown

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 [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

@mukeshpanchal27 mukeshpanchal27 left a comment

Copy link
Copy Markdown
Member

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.

Comment thread modules/images/webp-uploads/load.php
Comment thread modules/images/webp-uploads/load.php Outdated

@felixarntz felixarntz left a comment

Copy link
Copy Markdown
Member

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

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.

4 participants