Opened 10 months ago
Last modified 4 months ago
#49779 new enhancement
Add a filter that controls the size of the images on the Attachment pages
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | Awaiting Review | Priority: | normal |
Severity: | major | Version: | |
Component: | Media | Keywords: | |
Focuses: | Cc: |
Description
The images (attachments) on the Attachment pages are hardcoded as "medium".
On narrow themes, that might be fine, but on wider themes it leads to a tiny-looking image with a lot of awkward whitespace.
Many users have wanted to change the size of the image on that page, which has lead to multiple guides suggesting that they replace the hardcoded value in /wp-includes/post-template.php
Examples of such guides:
The problem with that solution, of course, is that the changes will be overwritten when the next WordPress update is released, leading to a lot of confused and frustrated users.
To fix that, we could apply a filter to the attachment size.
Original /wp-includes/post-template.php code:
$p .= wp_get_attachment_link( 0, 'medium', false ); $p .= '</p>';
Modified code:
$attachment_size = apply_filters( 'prepend_attachment_size', 'medium' ); $p .= wp_get_attachment_link( 0, $attachment_size, false ); $p .= '</p>';
After that, it's very easy for users to change the attachment image's size in their child theme's functions.php file.
Example:
add_filter('prepend_attachment_size', 'set_attachment_image_size_to_large'); function set_attachment_image_size_to_large() { return 'large'; }
Add attachment page image size filter to fix #49779