How to get id of the active menu item Wordpress?

How to get id of the active menu item for the current page?
April 4th 20 at 13:01
1 answer
April 4th 20 at 13:03
@Norene.Thi, This can be done by request, not necessarily to build the menu.
For example something like this:

$term_id = get_queried_object()->parent ;
$taxonomy_name = get_queried_object()->taxonomy;
foreach ( get_term_children( $term_id ,$taxonomy_name ) as $child ) {
 $term = get_term_by( 'id', $child, $taxonomy_name );
 echo '<li><a href="' . get_term_link( $child, $taxonomy_name ) . '">' . $term->name . '</a></li>';
}

Find more questions by tags WordPress