Menus: Introduce page_menu_link_attributes
filter in Walker_Page::start_el()
for the HTML attributes applied to a page menu item's anchor element.
This complements the `nav_menu_link_attributes` filter used in `Walker_Nav_Menu::start_el()`. Props pbiron. Fixes #40359. git-svn-id: https://develop.svn.wordpress.org/trunk@40565 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
c759785cea
commit
9e07667864
@ -160,10 +160,38 @@ class Walker_Page extends Walker {
|
|||||||
$args['link_before'] = empty( $args['link_before'] ) ? '' : $args['link_before'];
|
$args['link_before'] = empty( $args['link_before'] ) ? '' : $args['link_before'];
|
||||||
$args['link_after'] = empty( $args['link_after'] ) ? '' : $args['link_after'];
|
$args['link_after'] = empty( $args['link_after'] ) ? '' : $args['link_after'];
|
||||||
|
|
||||||
|
$atts = array();
|
||||||
|
$atts['href'] = get_permalink( $page->ID );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Filters the HTML attributes applied to a page menu item's anchor element.
|
||||||
|
*
|
||||||
|
* @since 4.8.0
|
||||||
|
*
|
||||||
|
* @param array $atts {
|
||||||
|
* The HTML attributes applied to the menu item's `<a>` element, empty strings are ignored.
|
||||||
|
*
|
||||||
|
* @type string $href The href attribute.
|
||||||
|
* }
|
||||||
|
* @param WP_Post $page Page data object.
|
||||||
|
* @param int $depth Depth of page, used for padding.
|
||||||
|
* @param array $args An array of arguments.
|
||||||
|
* @param int $current_page ID of the current page.
|
||||||
|
*/
|
||||||
|
$atts = apply_filters( 'page_menu_link_attributes', $atts, $page, $depth, $args, $current_page );
|
||||||
|
|
||||||
|
$attributes = '';
|
||||||
|
foreach ( $atts as $attr => $value ) {
|
||||||
|
if ( ! empty( $value ) ) {
|
||||||
|
$value = esc_attr( $value );
|
||||||
|
$attributes .= ' ' . $attr . '="' . $value . '"';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$output .= $indent . sprintf(
|
$output .= $indent . sprintf(
|
||||||
'<li class="%s"><a href="%s">%s%s%s</a>',
|
'<li class="%s"><a%s>%s%s%s</a>',
|
||||||
$css_classes,
|
$css_classes,
|
||||||
get_permalink( $page->ID ),
|
$attributes,
|
||||||
$args['link_before'],
|
$args['link_before'],
|
||||||
/** This filter is documented in wp-includes/post-template.php */
|
/** This filter is documented in wp-includes/post-template.php */
|
||||||
apply_filters( 'the_title', $page->post_title, $page->ID ),
|
apply_filters( 'the_title', $page->post_title, $page->ID ),
|
||||||
|
Loading…
Reference in New Issue
Block a user