Frans B Frans B - 2 months ago 5
jQuery Question

Hide div element with jquery on some wordpress pages

I want to hide certain divs for certain pages on my wordpress page. If I just use css it will hide this div in all my pages, which I do not want. I know how to do this for regular websites but not sure how to use this code for wordpress pages.

$(function(){
if (window.location.pathname == "mywebsite/Videos.html"||window.location.pathname == "url2.html"||window.location.pathname == "url3.html") {
$('#navleft').hide();
} else {
$('#navleft').show();
}


});

Im trying to add a similar code to this on my functions.php page.

Answer

You should do this in CSS only.

Find you're page(s) ID

Check the page source code, in the body tag there is a unique class with the page ID.

<body class="[...] page-id-XXX [...]">

Or, in your admin dashboard, go to Pages section. Find you're page and look the edit link, you'll find a post parameter (post=). It's the page ID.

Change you're CSS file

You could add those lines in your CSS file

.page-id-XX #navleft,
.page-id-YY #navleft {
  display: none;
}

where XX is your Videos.html page ID and so on.

Comments