Opened 10 years ago
Closed 8 years ago
#29237 closed enhancement (maybelater)
Add Link Size Parameter to Gallery Shortcode
Reported by: | cliffseal | Owned by: | DrewAPicture |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 3.9.2 |
Component: | Gallery | Keywords: | dev-feedback needs-patch |
Focuses: | Cc: |
Description
You can't currently choose what image size that each gallery image should _link to_ without some filtering hackery. This allows a linksize
parameter to be passed in the shortcode.
If this works, we could easily add it as a parameter in the modal when "Link to" is set to "Media File".
Attachments (4)
Change History (15)
#3
@
9 years ago
- Keywords needs-refresh needs-docs removed
Patch has now been refreshed and added additional docs
#4
@
9 years ago
Missed the @since doc string to reflect when the linksize attribute was added. Added in 29237.2.diff
#5
@
9 years ago
- Keywords has-patch added
- Milestone changed from Awaiting Review to 4.4
- Owner set to DrewAPicture
- Status changed from new to reviewing
@iamfriendly: One last request: Can you rename the new argument to 'linked_image_size'? Let's self-document a little more clearly :)
#7
@
9 years ago
- Keywords needs-patch added; has-patch removed
The more I look at this, the less I like the idea of introducing a new attribute. I think the one good viable option would be to allow the link
attribute to accept an image size. Passing 'full' would be the same as passing 'file', but that would be OK.
Also, the original patch over complicated generating the link. Pretty much all we'd have to do is handle the empty
and none
possibilities, then fall back to the image sizes.
For example:
<?php if ( ! empty( $atts['link'] ) ) { if ( 'none' === $attr['link'] ) { $image_output = wp_get_attachment_image( $id, $attr['size'], false, $attr ); } else { $size = 'file' === $attr['link'] ? 'full' : $attr['link']; $image_output = wp_get_attachment_link( $id, $size, false, false, false, $attr ); } } else { // $attr['link'] is empty, so just use $attr['size']. $image_output = wp_get_attachment_link( $id, $attr['size'], true, false, false, $attr ); }
#9
follow-up:
↓ 10
@
9 years ago
@DrewAPicture That seems doable. Would we still create an additional UI element to choose media size, or would image choices be integrated into the existing dropdown?
#10
in reply to:
↑ 9
@
9 years ago
Replying to cliffseal:
@DrewAPicture That seems doable. Would we still create an additional UI element to choose media size, or would image choices be integrated into the existing dropdown?
This is kind of the sticking point. There's already an option to choose an image size for the gallery display, and adding a second option while trying to clearly express the difference would be pretty likely to cause confusion.
In reality, this seems like a cool ability, but also pretty edge. My recommendation would be initially added support only for the attribute to accept an image size and handle outputting the correct links.
Of course, the attributes are also already filterable via the shortcode_atts_gallery hook, so it could be done programmatically as well.
If a plugin or theme wanted to extend that functionality into the Gallery UI, the print_media_template hook makes it possible to add a Backbone template. Jetpack uses that hook to add a "Type" drop-down for their Carousel module, for instance.
Patch needs a refresh after #22400 because of
if ( ! empty( $link ) && 'file' === $link )
changing to
if ( ! empty( $atts['link'] ) && 'file' === $atts['link'] )
Most
$link
calls have been wrapped in the$atts
variable now.Will also need docs for shortcode addition
linksize
.