Make WordPress Core

Changeset 55262


Ignore:
Timestamp:
02/07/2023 02:33:44 PM (17 months ago)
Author:
audrasjb
Message:

Media: Introduce wp_get_attachment_link_attributes filter.

This changeset introduces the wp_get_attachment_link_attributes hook to allow developers to filter the link attributes when getting the attachment link.

Props NathanAtmoz, aaroncampbell, antpb, costdev.
Fixes #41574.

Location:
trunk
Files:
1 added
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/post-template.php

    r55094 r55262  
    16671667    }
    16681668
    1669     $link_html = "<a href='" . esc_url( $url ) . "'>$link_text</a>";
     1669    /**
     1670     * Filters the list of attachment link attributes.
     1671     *
     1672     * @since 6.2.0
     1673     *
     1674     * @param array $attributes An array of attributes for the link markup,
     1675     *                          keyed on the attribute name.
     1676     * @param int   $id         Post ID.
     1677     */
     1678    $attributes = apply_filters( 'wp_get_attachment_link_attributes', array( 'href' => $url ), $_post->ID );
     1679
     1680    $link_attributes = '';
     1681    foreach ( $attributes as $name => $value ) {
     1682        $value            = 'href' === $name ? esc_url( $value ) : esc_attr( $value );
     1683        $link_attributes .= ' ' . esc_attr( $name ) . "='" . $value . "'";
     1684    }
     1685
     1686    $link_html = "<a$link_attributes>$link_text</a>";
    16701687
    16711688    /**
Note: See TracChangeset for help on using the changeset viewer.