Skip to content

Instantly share code, notes, and snippets.

@Ollo
Created June 13, 2012 16:50
Show Gist options
  • Save Ollo/2925224 to your computer and use it in GitHub Desktop.
Save Ollo/2925224 to your computer and use it in GitHub Desktop.
add class to parent in wordpress if page isn't in menu
function addOnStateToMenu() {
var slugIndex = getSlugIndex();
var menus = new Array('home','about-us','gsa-schedules', 'services', 'careers', 'case-studies','contact-us');
var parent = (window.location.pathname).split('/')[slugIndex];
$('#menuList li').each(function(index){
if ( parent === menus[index])
$(this).addClass('current-menu-parent');
});
}
function getSlugIndex() {
if (window.location.hostname.indexOf("localhost") != -1 ){
return 2;
}
else{
return 1;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment