Astra_Walker_Page::start_el( string $output, WP_Post $page, int $depth, array $args = array(), int $current_page )
Outputs the beginning of the current element in the tree.
Description
See also
Parameters
- $output
-
(string) (Required) Used to append additional content. Passed by reference.
- $page
-
(WP_Post) (Required) Page data object.
- $depth
-
(int) (Optional) Depth of page. Used for padding. Default 0.
- $args
-
(array) (Optional) Array of arguments.
Default value: array()
- $current_page
-
(int) (Optional) Page ID. Default 0.
Source
File: inc/core/class-astra-walker-page.php
public function start_el( &$output, $page, $depth = 0, $args = array(), $current_page = 0 ) {
$css_class = array( 'page_item', 'page-item-' . $page->ID );
$icon = '';
$mobile_icon = '';
if ( isset( $args['pages_with_children'][ $page->ID ] ) ) {
$css_class[] = 'menu-item-has-children';
$icon = Astra_Icons::get_icons( 'arrow' );
$icon = '<span role="presentation" class="dropdown-menu-toggle">' . $icon . '</span>';
// Add toggle button if menu is from Astra.
if ( true === is_object( $args ) ) {
if ( isset( $args->theme_location ) &&
( 'primary' === $args->theme_location ||
'above_header_menu' === $args->theme_location ||
'below_header_menu' === $args->theme_location )
) {
$mobile_icon = '<button ' . astra_attr(
'ast-menu-toggle',
array(
'aria-expanded' => 'false',
),
$page
) . '><span class="screen-reader-text">' . __( 'Menu Toggle', 'astra' ) . '</span>' . Astra_Icons::get_icons( 'arrow' ) . '</button>';
}
} else {
if ( isset( $page->post_parent ) && 0 === $page->post_parent ) {
$mobile_icon = '<button ' . astra_attr(
'ast-menu-toggle',
array(
'aria-expanded' => 'false',
),
$page
) . '><span class="screen-reader-text">' . __( 'Menu Toggle', 'astra' ) . '</span>' . Astra_Icons::get_icons( 'arrow' ) . '</button>';
}
}
}
if ( ! empty( $current_page ) ) {
$_current_page = get_post( $current_page );
if ( $_current_page && in_array( $page->ID, $_current_page->ancestors ) ) {
$css_class[] = 'current-menu-ancestor';
}
if ( $page->ID == $current_page ) {
$css_class[] = 'current-menu-item';
} elseif ( $_current_page && $page->ID == $_current_page->post_parent ) {
$css_class[] = 'current-menu-parent';
}
} elseif ( get_option( 'page_for_posts' ) == $page->ID ) {
$css_class[] = 'current-menu-parent';
}
$css_classes = implode( ' ', apply_filters( 'page_css_class', $css_class, $page, $depth, $args, $current_page ) );
$args['link_before'] = empty( $args['link_before'] ) ? '' : $args['link_before'];
$args['link_after'] = empty( $args['link_after'] ) ? '' : $args['link_after'];
$output .= sprintf(
'<li class="%s"><a href="%s" class="menu-link">%s%s%s%s</a>%s',
$css_classes,
get_permalink( $page->ID ),
$args['link_before'],
apply_filters( 'the_title', $page->post_title, $page->ID ),
$args['link_after'],
$icon,
$mobile_icon
);
}
Expand full source code Collapse full source code View on Trac
Changelog
| Version | Description |
|---|---|
| 1.7.2 | Introduced. |