How to load different menu based on current page in wordpress?

I have inherited a site from a new client who has a wordpress site that was heavily hand-coded by their previous webdev. The current code (in the header.php file) is:

//When page loads...
    $(".tab").hide(); //Hide all content
//Find URL location
var idToShow = location.pathname.split("/")[1];
//If URL location is one of these, then show its proper menu. If it isn't just show the home's menu.
if (idToShow == "unknown" || idToShow == "home" || idToShow == "parish" || idToShow == "formation" || idToShow == "school" || idToShow == "youth-ministry" || idToShow == "councils" || idToShow == "committees" || idToShow == "organizationsactivites" || idToShow == "contact") {
    $("#nav li."+idToShow).addClass("current").show(); //Activate first tab
    $("#"+idToShow).show();
}
else {
    $("#nav li.home").addClass("current").show(); //Activate first tab
    $("#home").show();
}

I am in the process of moving this site to a new host, and this works on the old host, but not the new host. I’m not sure where I could look for error logs (if there are any) or any other information that would help me solve this. Any ideas? Thanks!

Related posts

Leave a Reply

1 comment

  1. $(function() {
    //When page loads...
        $(".tab").hide(); //Hide all content
    //Find URL location
    var idToShow = location.pathname.split("/")[1];
    //If URL location is one of these, then show its proper menu. If it isn't just show the home's menu.
    if (idToShow == "unknown" || idToShow == "home" || idToShow == "parish" || idToShow == "formation" || idToShow == "school" || idToShow == "youth-ministry" || idToShow == "councils" || idToShow == "committees" || idToShow == "organizationsactivites" || idToShow == "contact") {
        $("#nav li."+idToShow).addClass("current").show(); //Activate first tab
        $("#"+idToShow).show();
    }
    else {
        $("#nav li.home").addClass("current").show(); //Activate first tab
        $("#home").show();
    }
    });
    

    Hello, try this. This will solve your problem.