// Check if menu exists if ( $menu_items = wp_get_nav_menu_items( 'menu' ) ) { // Loop over menu items foreach ( $menu_items as $menu_item ) { // Compare menu object with current page menu object $current = ( $menu_item->object_id == get_queried_object_id() ) ? 'current' : ''; // Print menu item echo '<li class="' . $current . '"><a href="' . $menu_item->url . '">' . $menu_item->title . '</a></li>'; } }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter