• Hi!

    I am trying to use javascript to make a page entitled Projects “active” when on each the single post page.

    I am placing this code on the top of the single.php before it gets the header (which includes the project link).

    <script>
    jQuery(document).ready(function(){
    $(“#menu-item-19”).children(“a”).addClass(“current_page_item”);
    });
    </script>

    Where #menu-item-19 is the id of the li that includes the link to the projects page.

    Any idea why the link isn’t getting the class “current_page_item”?

    Thanks in advance!

Viewing 1 replies (of 1 total)
  • It should work. WordPress applies the class to the “li” though, rather than the “a”, so perhaps that’s where the conufsion was.

    $(‘#menu-item-19’).addClass(‘current_page_item’);

Viewing 1 replies (of 1 total)

The topic ‘Adding Class current_page_item to main menu using Javascript’ is closed to new replies.