APD Toronto
asked on
Exclude JS From Running on 2 Body Classes
Hi Experts,
I'm working on www.iwscc.ca and I would like a block of code to run on all pages, except https://iwscc.ca/blog-posts/ (page-id-2956) and for all posts that derive from it (single-post).
I have started the following:
The issue is that this works on the Blog page (ie- "embed" is not logged), but it doesn't on the posts (ie- "embed" is logged).
What am I doing wrong?
I'm working on www.iwscc.ca and I would like a block of code to run on all pages, except https://iwscc.ca/blog-posts/ (page-id-2956) and for all posts that derive from it (single-post).
I have started the following:
if (!($('body').hasClass('page-id-2956')) || !($('body').hasClass('single-post'))){
console.log('embed');
}
The issue is that this works on the Blog page (ie- "embed" is not logged), but it doesn't on the posts (ie- "embed" is logged).
What am I doing wrong?
I think you have your logic mixed up. You are saying run this code if the page does not have 'page-id-2956' or it doesn't have 'single-post'. If I am understanding correctly you want it to be this page does not have 'page-id-2956' or 'single-post. Something like below.
if (!(($('body').hasClass('page-id-2956')) || ($('body').hasClass('single-post')))){
console.log('embed');
}
ASKER
@Jeffery, I don’t Understand.
I want the code NOT to run if any page has either of those classes
I want the code NOT to run if any page has either of those classes
use this one
https://jsfiddle.net/HainKurt/e5x7w2ah/
https://jsfiddle.net/HainKurt/e5x7w2ah/
if (!(($('body').hasClass('page-id-2956')) || ($('body').hasClass('single-post')))) {
console.log('embed');
}
Yes, that is why I moved the ! (or not) outside the parenthesis. The way you had it written before it was still running the code within the if block if either class was not present. You only wanted it to run if both are not present.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Chrome : right-click / inspect
I can see embed on both page, maybe clear your browser cache..