astra_page_css_class( array $css_class, WP_Post $page, int $depth, array $args, int $current_page )

Add CSS classes from wp_nav_menu the wp_page_menu()’s menu items.


Description

This will help avoid targeting wp_page_menu and wp_nav_manu separately in CSS/JS.


Parameters

$css_class

(array) (Required) An array of CSS classes to be applied to each list item.

$page

(WP_Post) (Required) Page data object.

$depth

(int) (Required) Depth of page, used for padding.

$args

(array) (Required) An array of arguments.

$current_page

(int) (Required) ID of the current page.


Return

(Array) CSS classes with added menu class menu-item


Source

File: inc/markup-extras.php

function astra_page_css_class( $css_class, $page, $depth, $args, $current_page ) {
	$css_class[] = 'menu-item';

	if ( isset( $args['pages_with_children'][ $page->ID ] ) ) {
		$css_class[] = 'menu-item-has-children';
	}

	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';
	}

	return $css_class;
}

Changelog

Changelog
Version Description
1.6.9 Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.