OnPoint Plugins

  • Plugins
    • Advanced Sidebar Menu
    • Go Live Update Urls
  • About
    • Services
    • Showcase
  • Blog
  • Contact
  • Support
  • Log In
← Back to support

Manually set “Current” page in menu

Resolved

Requested: 4 years and 10 months ago

Hi Mat,

I just bought the Pro version so I can manually display the menu for a top level page while on a post type, and it works great.  Here’s a sample blog post with the correct page menu displaying:

https://robinsoncenter.uw.edu/2018/03/looking-explore-something-new-summer/

The problem is that it would be even better to have the “News” item in this menu with a class of “current_page_item” so it’s highlighted appropriately.  Is there a way to do this in the settings or using hooks and PHP?

I didn’t see anything in the documentation, so I’m hoping you can point me in the right direction.  Thanks.

– Chris Blair

Plugin: Advanced Sidebar Menu

  1. OnPoint Plugins

    4 years and 10 months ago

    Hi Chris,

    Certainly. Using the following filter will add the “current_page_item” class to the “News” page always.

    add_filter( 'page_css_class', 'mark_news_as_current_page', 15, 2 );
    function mark_news_as_current_page( $css_class, $page ) {
       if ( 111 === (int) $page->ID ) {
          $css_class[] = 'current_page_item';
       }
       return $css_class;
    }
  2. info22

    4 years and 10 months ago

    Thanks, Mat, that’s just what I needed.  Works great!

New Response Cancel reply

You must be logged in to respond. Only PRO members are allowed to respond to support requests.

© 2023 · WordPress Development · Terms Of Service · Privacy Policy · Cookie Policy · Log in

  • Plugins
  • Blog
  • Contact