Skip to content

Instantly share code, notes, and snippets.

@Farmatique
Last active March 17, 2017 13:45
Show Gist options
  • Save Farmatique/8078b41361add4f6203d81f75f5310c8 to your computer and use it in GitHub Desktop.
Save Farmatique/8078b41361add4f6203d81f75f5310c8 to your computer and use it in GitHub Desktop.
add custom element inside menu-element in wordpress
add_filter('wp_nav_menu_items','add_language_select_to_footer_menu', 'icl_post_languages', 10, 2);
function add_language_select_to_footer_menu( $items, $args) {
if( $args->theme_location == 'footer-menu' ){ // choose name of the menu to apply
$menuID = 'footer';
$primaryNav = wp_get_nav_menu_items($menuID);
echo '<ul id="menu-footer" class="nav navbar-nav">';
for ( $i = 0; $i < count($primaryNav); ++$i) {
if($i == 4){ //choose element of the menu to apply
echo '<li><a href="'.$primaryNav[$i]->url.'" title="'.$primaryNav[$i]->title.'">'.$primaryNav[$i]->title.icl_post_languages().'</a></li>';
} else {
echo '<li><a href="'.$primaryNav[$i]->url.'" title="'.$primaryNav[$i]->title.'">'.$primaryNav[$i]->title.'</a></li>';
}
}
echo '</ul>';
} else {
return $items;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment