1

I am attempting to write a small script which will look at page URL and, based on what URL it sees, add a new class to an HTML element. More specifically, on this page:

http://pamaphilly.wpengine.com/volunteer/

I'm going to add a class for the active URL which will add an arrow marker to the appropriate left hand nav marker. I have tried this strategy: jQuery add class based on page URL and, when I used the script on a dummy page, it works fine. But when I try adding it to the Wordpress Template, nothing happens. I've tried adding the script at the bottom of the template file and just (as a test) embedding it in the php template. I'm guessing my failure relates to a Wordpress issues (probably a failure of knowledge on how to do this) but I would appreciate any guidance.

Thanks.

1
  • The question you linked to has the right approach and its seems like you have the correct implementation. The page on your site contains JavaScript errors which is the reason why it's not functioning: "Error: TypeError: $(...).slick is not a function" Commented Oct 25, 2014 at 20:09

2 Answers 2

0

You need to include .slick before you can use it. (before script.js + in the same way you include your script.js file)

Sign up to request clarification or add additional context in comments.

Comments

0

Why not do this with CSS and WordPress directly, and skip JavaScript?

You can use WordPress's body_class() function to dynamically add a class to the <body> of your page. Using CSS, you can then target your appropriate .volunteer .sidebar-member li via CSS.

1 Comment

This does seem like a more common sense approach. I'll look into it and thanks to you and others who answered.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.