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

Classic Editor Images with Captions are 10px under actual width #597

Open
diggeddy opened this issue Feb 1, 2024 · 0 comments
Open

Classic Editor Images with Captions are 10px under actual width #597

diggeddy opened this issue Feb 1, 2024 · 0 comments
Labels
bug Bugs, unexpected and weird behaviors

Comments

@diggeddy
Copy link
Collaborator

diggeddy commented Feb 1, 2024

Install Classic editor and add 2 same size images to a page.
One with caption and one without

Screenshot 2024-02-01 at 13 59 18

The figure element is given a inline width that is 10px undersize due to this function:

if ( ! function_exists( 'generate_remove_caption_padding' ) ) {
add_filter( 'img_caption_shortcode_width', 'generate_remove_caption_padding' );
/**
* Remove WordPress's default padding on images with captions
*
* @param int $width Default WP .wp-caption width (image width + 10px).
* @return int Updated width to remove 10px padding.
*/
function generate_remove_caption_padding( $width ) {
return $width - 10;
}

Which is legacy function to fix the extra 10px addd to the figure by the img_caption_shortcode core function:
But the extra 10px was removed here:

https://github.com/WordPress/wordpress-develop/blob/8338c630284124bbe79dc871822d6767e3b45f0b/src/wp-includes/media.php#L2427

For now users can remove the filter like so:

add_action('wp', function(){
	remove_filter( 'img_caption_shortcode_width', 'generate_remove_caption_padding' );	
});

But should we consider deprecating this ? Or leave it as is ?

@github-actions github-actions bot added the triage Awaiting review label Feb 1, 2024
@diggeddy diggeddy added bug Bugs, unexpected and weird behaviors and removed triage Awaiting review labels Feb 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Bugs, unexpected and weird behaviors
Projects
None yet
Development

No branches or pull requests

1 participant