mirror of
https://github.com/WordPress/WordPress.git
synced 2025-01-08 17:38:26 +01:00
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. Built from https://develop.svn.wordpress.org/trunk@40565 git-svn-id: http://core.svn.wordpress.org/trunk@40434 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
42845bcb2d
commit
4995062686
@ -160,10 +160,38 @@ class Walker_Page extends Walker {
|
||||
$args['link_before'] = empty( $args['link_before'] ) ? '' : $args['link_before'];
|
||||
$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(
|
||||
'<li class="%s"><a href="%s">%s%s%s</a>',
|
||||
'<li class="%s"><a%s>%s%s%s</a>',
|
||||
$css_classes,
|
||||
get_permalink( $page->ID ),
|
||||
$attributes,
|
||||
$args['link_before'],
|
||||
/** This filter is documented in wp-includes/post-template.php */
|
||||
apply_filters( 'the_title', $page->post_title, $page->ID ),
|
||||
|
@ -4,7 +4,7 @@
|
||||
*
|
||||
* @global string $wp_version
|
||||
*/
|
||||
$wp_version = '4.8-alpha-40564';
|
||||
$wp_version = '4.8-alpha-40565';
|
||||
|
||||
/**
|
||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||
|
Loading…
Reference in New Issue
Block a user