Filter hook 'page_menu_link_attributes'

in WP Core File wp-includes/class-walker-page.php at line 190

View Source

page_menu_link_attributes

Filter Hook
Description
Filters the HTML attributes applied to a page menu item's anchor element. }

Hook Information

File Location wp-includes/class-walker-page.php View on GitHub
Hook Type Filter
Line Number 190

Hook Parameters

Type Name Description
array $atts { The HTML attributes applied to the menu item's `` element, empty strings are ignored.
WP_Post $page Page data object.
int $depth Depth of page, used for padding.
array $args An array of arguments.
int $current_page_id ID of the current page.

Usage Examples

Basic Usage
<?php
// Hook into page_menu_link_attributes
add_filter('page_menu_link_attributes', 'my_custom_filter', 10, 5);

function my_custom_filter($atts, $page, $depth, $args, $current_page_id) {
    // Your custom filtering logic here
    return $atts;
}

Source Code Context

wp-includes/class-walker-page.php:190 - How this hook is used in WordPress core
<?php
 185  		 * @param WP_Post $page            Page data object.
 186  		 * @param int     $depth           Depth of page, used for padding.
 187  		 * @param array   $args            An array of arguments.
 188  		 * @param int     $current_page_id ID of the current page.
 189  		 */
 190  		$atts = apply_filters( 'page_menu_link_attributes', $atts, $page, $depth, $args, $current_page_id );
 191  
 192  		$attributes = '';
 193  		foreach ( $atts as $attr => $value ) {
 194  			if ( is_scalar( $value ) && '' !== $value && false !== $value ) {
 195  				$value       = ( 'href' === $attr ) ? esc_url( $value ) : esc_attr( $value );

PHP Documentation

<?php
/**
		 * 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.
		 *     @type string $aria-current The aria-current 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 ID of the current page.
		 */
Quick Info
  • Hook Type: Filter
  • Parameters: 5
  • File: wp-includes/class-walker-page.php
Related Hooks

Related hooks will be displayed here in future updates.