Walker_Page::start_el( string $output, WP_Post $data_object, int $depth = 0, array $args = array(), int $current_object_id = 0 )
- Since
- 2.1.0, 5.9.0
- Source
wp-includes/class-walker-page.php:105
Outputs the beginning of the current element in the tree.
Parameters
$outputstring- Used to append additional content. Passed by reference.
$data_objectWP_Post- Page data object.
$depthintoptional- Depth of page. Used for padding. Default 0.Default:
0 $argsarrayoptional- Array of arguments. Default empty array.Default:
array() $current_object_idintoptional- ID of the current page. Default 0.Default:
0
Hooks fired · 3
3 hooks fire while Walker_Page::start_el() runs, in this order:
- apply_filters( page_css_class )filterline 159 (+54 into the body)
Filters the list of CSS classes to include with each page item in the list.
- apply_filters( page_menu_link_attributes )filterline 190 (+85 into the body)
Filters the HTML attributes applied to a page menu item's anchor element.
Uses · 8
- get_post()Retrieves post data given a post ID or post object.
- get_option()Retrieves an option value based on an option name.
- apply_filters()Calls the callback functions that have been added to a filter hook.
- esc_attr()Escaping for HTML attributes.
- __()Retrieves the translation of $text.
- get_permalink()Retrieves the full permalink for the current post or post ID.
- esc_url()Checks and cleans a URL.
- mysql2date()Converts given MySQL date string into a different format.
Source
public function start_el( &$output, $data_object, $depth = 0, $args = array(), $current_object_id = 0 ) { // Restores the more descriptive, specific name for use within this method. $page = $data_object; $current_page_id = $current_object_id; if ( isset( $args['item_spacing'] ) && 'preserve' === $args['item_spacing'] ) { $t = "\t"; $n = "\n"; } else { $t = ''; $n = ''; } if ( $depth ) { $indent = str_repeat( $t, $depth ); } else { $indent = ''; } $css_class = array( 'page_item', 'page-item-' . $page->ID ); if ( isset( $args['pages_with_children'][ $page->ID ] ) ) { $css_class[] = 'page_item_has_children'; } if ( ! empty( $current_page_id ) ) { $_current_page = get_post( $current_page_id ); if ( $_current_page && in_array( $page->ID, $_current_page->ancestors, true ) ) { $css_class[] = 'current_page_ancestor'; } if ( $page->ID === (int) $current_page_id ) { $css_class[] = 'current_page_item'; } elseif ( $_current_page && $page->ID === $_current_page->post_parent ) { $css_class[] = 'current_page_parent'; } } elseif ( (int) get_option( 'page_for_posts' ) === $page->ID ) { $css_class[] = 'current_page_parent'; } /** * Filters the list of CSS classes to include with each page item in the list. * * @since 2.8.0 * * @see wp_list_pages() * * @param string[] $css_class An array of CSS classes to be applied to each list item. * @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. */ $css_classes = implode( ' ', apply_filters( 'page_css_class', $css_class, $page, $depth, $args, $current_page_id ) ); $css_classes = $css_classes ? ' class="' . esc_attr( $css_classes ) . '"' : ''; if ( '' === $page->post_title ) { /* translators: %d: ID of a post. */ $page->post_title = sprintf( __( '#%d (no title)' ), $page->ID ); } $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 ); $atts['aria-current'] = ( $page->ID === (int) $current_page_id ) ? 'page' : ''; /** * 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. * }History
Introduced in 2.1.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
5.9.0
Renamed
$page to $data_object and $current_page to $current_object_id to match parent class for PHP 8 named parameter support.from the docblock2.1.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-page.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.