Opened 13 years ago
Closed 3 months ago
#22075 closed enhancement (worksforme)
Allow custom attributes to be set in `wp_get_attachment_link`
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Milestone: | Priority: | normal | |
| Severity: | normal | Version: | 3.4 |
| Component: | Media | Keywords: | |
| Focuses: | Cc: |
Description
I answered a question not so long ago on WordPress StackExchange.
There I saw the need on a filter for wp_get_attachment_link() to allow the developer to add or remove attributes to the HTML without having to use a regex on it or creating the a tag again.
So I've done this small patch with changes to apply this enhancement to the function.
Attachments (3)
Change History (14)
#4
@
12 years ago
- Keywords has-patch removed
Sure, sounds valid.
I'm not a fan of daisy chaining more parameters onto the function's signature. Perhaps we could consider moving over to an array hash while supporting backwards compatibility a la BuddyPress?
#5
@
12 years ago
- Summary changed from Improving `wp_get_attachment_link` to Allow custom attributes to be set in `wp_get_attachment_link`
#6
@
12 years ago
attachment:22075.3.diff changes the function to take an array hash as the only parameter, with backwards compatibility inspired by BuddyPress.
#7
follow-up:
↓ 8
@
12 years ago
After thinking about this for a bit, I'm not sure we want to tack on more options to this function.
The question from WPSE asks "how do I customize the output of the gallery shortcode to look nothing like what it does out of the box," and in all honesty if you want to do that, you should probably do it via the post_gallery shortcode.
To the topic at hand, if you want to add custom attributes to the anchor tag in wp_get_attachment_link(), you should probably use the wp_get_attachment_link filter and instead of regexing just rebuild the string however you see fit.
#8
in reply to:
↑ 7
@
12 years ago
Replying to ericlewis:
To the topic at hand, if you want to add custom attributes to the anchor tag in
wp_get_attachment_link(), you should probably use thewp_get_attachment_linkfilter and instead of regexing just rebuild the string however you see fit.
I tend to agree. It's a short function, there's not much to rebuild.
#10
@
5 months ago
- Keywords close added
Hi all,
Just looking over this ticket now, and it's been a while so thought I would update the state of this function as it stands now. I have compared the function between 3.4 and the latest release and there has been a good deal of changes in here since this ticket was raised, including a filter for attributes applied to the output html:
<?php /** * Filters the list of attachment link attributes. * * @since 6.2.0 * * @param array $attributes An array of attributes for the link markup, * keyed on the attribute name. * @param int $id Post ID. */ $attributes = apply_filters( 'wp_get_attachment_link_attributes', array( 'href' => $url ), $_post->ID );
As of such I believe this issue has been rectified within the code, and is no longer in need of a patch, and I have marked this ticket with the close tag. Please feel free to come back on this ticket if you believe otherwise, and we can continue the conversation further. 😃
#11
@
3 months ago
- Keywords dev-feedback has-patch needs-refresh needs-unit-tests close removed
- Resolution set to worksforme
- Status changed from new to closed
Hi all, as Callum pointed out above, there's now a filter in this function that allows customizing the attributes. It looks like we can close this ticket now.
post-template.php