Accessibility: Introduce category_list_link_attributes
filter in Walker_Category::start_el()
for the HTML attributes applied to a category list item's anchor element.
This complements the `page_menu_link_attributes` filter in `Walker_Page::start_el()` and the `nav_menu_link_attributes` filter in `Walker_Nav_Menu::start_el()`. Props pbiron, audrasjb, afercia. Fixes #40666. See #40359. git-svn-id: https://develop.svn.wordpress.org/trunk@44957 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
fb93cedcd8
commit
ae0605b323
@ -108,7 +108,9 @@ class Walker_Category extends Walker {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$link = '<a href="' . esc_url( get_term_link( $category ) ) . '" ';
|
$atts = array();
|
||||||
|
$atts['href'] = get_term_link( $category );
|
||||||
|
|
||||||
if ( $args['use_desc_for_title'] && ! empty( $category->description ) ) {
|
if ( $args['use_desc_for_title'] && ! empty( $category->description ) ) {
|
||||||
/**
|
/**
|
||||||
* Filters the category description for display.
|
* Filters the category description for display.
|
||||||
@ -118,11 +120,40 @@ class Walker_Category extends Walker {
|
|||||||
* @param string $description Category description.
|
* @param string $description Category description.
|
||||||
* @param object $category Category object.
|
* @param object $category Category object.
|
||||||
*/
|
*/
|
||||||
$link .= 'title="' . esc_attr( strip_tags( apply_filters( 'category_description', $category->description, $category ) ) ) . '"';
|
$atts['title'] = strip_tags( apply_filters( 'category_description', $category->description, $category ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
$link .= '>';
|
/**
|
||||||
$link .= $cat_name . '</a>';
|
* Filters the HTML attributes applied to a category list item's anchor element.
|
||||||
|
*
|
||||||
|
* @since 5.2.0
|
||||||
|
*
|
||||||
|
* @param array $atts {
|
||||||
|
* The HTML attributes applied to the list item's `<a>` element, empty strings are ignored.
|
||||||
|
*
|
||||||
|
* @type string $href The href attribute.
|
||||||
|
* @type string $title The title attribute.
|
||||||
|
* }
|
||||||
|
* @param WP_Term $category Term data object.
|
||||||
|
* @param int $depth Depth of category, used for padding.
|
||||||
|
* @param array $args An array of arguments.
|
||||||
|
* @param int $id ID of the current category.
|
||||||
|
*/
|
||||||
|
$atts = apply_filters( 'category_list_link_attributes', $atts, $category, $depth, $args, $id );
|
||||||
|
|
||||||
|
$attributes = '';
|
||||||
|
foreach ( $atts as $attr => $value ) {
|
||||||
|
if ( ! empty( $value ) ) {
|
||||||
|
$value = ( 'href' === $attr ) ? esc_url( $value ) : esc_attr( $value );
|
||||||
|
$attributes .= ' ' . $attr . '="' . $value . '"';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$link = sprintf(
|
||||||
|
'<a%s>%s</a>',
|
||||||
|
$attributes,
|
||||||
|
$cat_name
|
||||||
|
);
|
||||||
|
|
||||||
if ( ! empty( $args['feed_image'] ) || ! empty( $args['feed'] ) ) {
|
if ( ! empty( $args['feed_image'] ) || ! empty( $args['feed'] ) ) {
|
||||||
$link .= ' ';
|
$link .= ' ';
|
||||||
@ -134,6 +165,7 @@ class Walker_Category extends Walker {
|
|||||||
$link .= '<a href="' . esc_url( get_term_feed_link( $category->term_id, $category->taxonomy, $args['feed_type'] ) ) . '"';
|
$link .= '<a href="' . esc_url( get_term_feed_link( $category->term_id, $category->taxonomy, $args['feed_type'] ) ) . '"';
|
||||||
|
|
||||||
if ( empty( $args['feed'] ) ) {
|
if ( empty( $args['feed'] ) ) {
|
||||||
|
/* translators: %s: category name */
|
||||||
$alt = ' alt="' . sprintf( __( 'Feed for all posts filed under %s' ), $cat_name ) . '"';
|
$alt = ' alt="' . sprintf( __( 'Feed for all posts filed under %s' ), $cat_name ) . '"';
|
||||||
} else {
|
} else {
|
||||||
$alt = ' alt="' . $args['feed'] . '"';
|
$alt = ' alt="' . $args['feed'] . '"';
|
||||||
|
Loading…
Reference in New Issue
Block a user