Walker_Nav_Menu
- Since
- 3.0.0
- Source
wp-includes/class-walker-nav-menu.php:17
Core class used to implement an HTML list of nav menu items.
Compatibility
- WordPress
- since 3.0.0
- 6.7.7
- 6.8.8
- 6.9.7
- 7.0.4
- 7.1.0
Present in every tracked release (6.7.7 to 7.1.0).
Hooks and filters fired · 10
Every hook that fires from inside Walker_Nav_Menu, in the order it appears in the class, grouped by the method that fires it.
Walker_Nav_Menu::start_lvl()
- apply_filters( nav_menu_submenu_css_class )filter line 92
- apply_filters( nav_menu_submenu_attributes )filter line 110
Walker_Nav_Menu::start_el()
- apply_filters( nav_menu_item_args )filter line 181
- apply_filters( nav_menu_css_class )filter line 194
- apply_filters( nav_menu_item_id )filter line 207
- apply_filters( nav_menu_item_attributes )filter line 228
- apply_filters( the_title )filter line 234
- apply_filters( nav_menu_item_title )filter line 249
- apply_filters( nav_menu_link_attributes )filter line 297
- apply_filters( walker_nav_menu_start_el )filter line 320
Properties · 3
$tree_typestringpublic- What the class handles.
$db_fieldsstring[]public- Database fields to use.
$privacy_policy_urlstringprivate- The URL to the privacy policy page.
Methods · 6
- __construct()Constructor.
- start_lvl()Starts the list before the elements are added.
- end_lvl()Ends the list of after the elements are added.
- start_el()Starts the element output.
- end_el()Ends the element output, if needed.
- build_atts()Builds a string of HTML attributes from an array of key/value pairs.
Source code
class Walker_Nav_Menu extends Walker { /** * What the class handles. * * @since 3.0.0 * @var string * * @see Walker::$tree_type */ public $tree_type = array( 'post_type', 'taxonomy', 'custom' ); /** * Database fields to use. * * @since 3.0.0 * @todo Decouple this. * @var string[] * * @see Walker::$db_fields */ public $db_fields = array( 'parent' => 'menu_item_parent', 'id' => 'db_id', ); /** * The URL to the privacy policy page. * * @since 6.8.0 * @var string */ private $privacy_policy_url; /** * Constructor. * * @since 6.8.0 */ public function __construct() { $this->privacy_policy_url = get_privacy_policy_url(); } /** * Starts the list before the elements are added. * * @since 3.0.0 * * @see Walker::start_lvl() * * @param string $output Used to append additional content (passed by reference). * @param int $depth Depth of menu item. Used for padding. * @param stdClass $args An object of wp_nav_menu() arguments. */ public function start_lvl( &$output, $depth = 0, $args = null ) { if ( isset( $args->item_spacing ) && 'discard' === $args->item_spacing ) { $t = ''; $n = ''; } else { $t = "\t"; $n = "\n"; } $indent = str_repeat( $t, $depth ); // Default class. $classes = array( 'sub-menu' ); /** * Filters the CSS class(es) applied to a menu list element. * * @since 4.8.0 * * @param string[] $classes Array of the CSS classes that are applied to the menu `<ul>` element. * @param stdClass $args An object of `wp_nav_menu()` arguments. * @param int $depth Depth of menu item. Used for padding. */ $class_names = implode( ' ', apply_filters( 'nav_menu_submenu_css_class', $classes, $args, $depth ) ); $atts = array(); $atts['class'] = ! empty( $class_names ) ? $class_names : '';Changelog
Introduced in 3.0.0. One change between 6.7.7 and 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
6.8.8
Method
__construct() added.verified against source3.0.0
Introduced.from the docblock
About this page
- Parsed data
- Generated from the wordpress-develop 6.8.8 tag, from
src/wp-includes/class-walker-nav-menu.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it. - Corrections
- Something wrong on this page? Report it and it gets fixed in the next regeneration.