Skip to content

Instantly share code, notes, and snippets.

@ocReaper
Last active May 30, 2016 14:41
Show Gist options
  • Save ocReaper/b9c0a9a68f6232b0be63286220e94fe5 to your computer and use it in GitHub Desktop.
Save ocReaper/b9c0a9a68f6232b0be63286220e94fe5 to your computer and use it in GitHub Desktop.
Creating a WPML compatible WordPress menu without a walker class
<?php
$menus = wp_get_nav_menus();
foreach ($menus as $menu) {
if (ICL_LANGUAGE_CODE === 'en') {
$top_menu_search_name = 'top-menu';
} else {
$language_name = strtolower(ICL_LANGUAGE_NAME);
$language_name = str_replace(' ', '-', $language_name);
$language_name = str_replace('/-', '', $language_name);
$top_menu_search_name = 'top-menu-' . $language_name;
}
if ( $menu->slug == $top_menu_search_name ) {
$top_menu_id = $menu->term_id;
break;
}
}
$top_menu_items = wp_get_nav_menu_items( $top_menu_id );
if ( is_array( $top_menu_items ) ) :
foreach ( $top_menu_items as $top_key => $top_menu_item ) : ?>
<div class="nav-list-item">
<a href="<?= $top_menu_item->url ?>">
<?= $top_menu_item->title ?>
</a>
</div>
<? endforeach;
endif; ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment