• Hello,

    i hope this is the right forum. I’ve been reading a lot of topics about highlighting the parent of a menu but so far my question never seemed resolved.

    I made my menu without using the wp_links, i made my navigation list manually.

    Now I would like to achieve that if you click on an inline link inside a page to a page on the site that it adds “.current_page_parent” so that you see visually you are still in the same site section.

    Ill try to make myself a bit more clear:

    Say i have a page:
    http://www.site.com/portfolio (i see my navigation “portfolio” highlighted)

    and on that page there is a list with links to different works,
    then i click on one of those links
    http://www.site.com/portfolio/work23

    i would like to see my menu item “portfolio” still being highlighted when i am located on a sub page.

    Is there a way to add “.current_page_parent” to links via a function in my functions.php? or is that not he way?

    Thanks a lot!

Viewing 4 replies - 1 through 4 (of 4 total)
  • You can use the if(is_tree()) function prescribed here in place of the if(is_page()) that you are probably using.

    So, at the moment you have something like
    <?php if(is_page("id")) echo 'class="current_page_parent"'; ?>

    Adding the function is_tree() to your functions.php will allow you to change the above to
    <?php if(is_tree("id")) echo 'class="current_page_parent"'; ?>

    The function is_tree() tests a) that the user is looking at a page, b) to see if they are looking at the page with the id, and c) to see if they are looking at a sub-page of that id.

    Thread Starter sdrib

    (@sdrib)

    Thanks a lot, this is giving me very positive results m going to try to work it out further.

    Thread Starter sdrib

    (@sdrib)

    This works perfect!! Thank you a lot!

    Thread Starter sdrib

    (@sdrib)

    Sorry to bump this topic. But if anyone is ever interested in how to achieve the same thing for ‘sub sub pages’ etc of a parent page check out this function

    click

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘How to add a .current_page_parent to any link with a function?’ is closed to new replies.