• Skip to main content
  • Skip to forum navigation

StudioPress

  • Shop for Themes
  • My StudioPress

Forum navigation

  • Home
  • General Genesis Discussions
  • StudioPress Themes
  • Genesis Blocks
    • Genesis Blocks
    • Genesis Custom Blocks
  • Retired Themes
  • FAQs
  • Forum Rules
  • Internationalization and Translations
  • Forum Bugs and Suggestions
  • Forum Log In

Are You Using The WordPress Block Editor?

Genesis now offers plugins that help you build better sites faster with the WordPress block editor (Gutenberg). Try the feature-rich free versions of each plugin for yourself!

Genesis Blocks Genesis Custom Blocks

Active menu state when on blog posts

Welcome!

These forums are for general discussion on WordPress and Genesis. Official support for StudioPress themes is offered exclusively at My StudioPress. Responses in this forum are not guaranteed. Please note that this forum will require a new username, separate from the one used for My.StudioPress.

Log In
Register Lost Password

Community Forums › Forums › Archived Forums › General Discussion › Active menu state when on blog posts

This topic is: not resolved

Tagged: css, header, menu, php

  • This topic has 2 replies, 2 voices, and was last updated 3 years, 6 months ago by laucocos.
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • September 18, 2019 at 9:49 am #493614
    laucocos
    Participant

    On my website, I have active state that puts a line under the relevant item on the menu when that page is active. This works fine on all the pages, including the blog page https://staging2.staging.inspiratti.com/blog-page-grid/

    However, I want to make it so that the ‘Blog’ menu item to be marked active any time someone is on a blog article, category page, etc. e.g. https://staging2.staging.inspiratti.com/why-social-media-is-like-going-to-the-gym/327/

    I added the following code to functions.php but it has no affect.

    function be_menu_item_classes( $classes, $item, $args ) {
    if( 'header' !== $args->theme_location )
    return $classes;
    if( ( is_singular( 'post' ) || is_category() || is_tag() ) && 'Blog' == $item->title )
    $classes[] = 'current-menu-item';

    return array_unique( $classes );
    }
    add_filter( 'nav_menu_css_class', 'be_menu_item_classes', 10, 3 );

    https://staging2.staging.inspiratti.com/blog-page-grid/
    September 19, 2019 at 7:23 am #493636
    Victor Font
    Moderator

    The code you are using is designed to work with a menu in the header location. Without seeing how your menu locations are defined, the code is probably wrong for your site. Change the word "header" to the location of your target menu and it should work.


    Regards,

    Victor
    https://victorfont.com/
    Call us toll free: 844-VIC-FONT (842-3668)
    Have you requested your free website audit yet?

    September 19, 2019 at 7:56 am #493637
    laucocos
    Participant

    Thanks for your response. I'm not sure how to find this out. In the style.css file there is reference to .site-header - could that work?

    I'm using the Infinity Pro theme as a basis. Do you now if the menu is set up differently, and if so how?

  • Author
    Posts
Viewing 3 posts - 1 through 3 (of 3 total)
  • The forum ‘General Discussion’ is closed to new topics and replies.

CTA

Ready to get started? Create a site or shop for themes.

Create a site with WP EngineShop for Themes

Footer

StudioPress

© 2023 WPEngine, Inc.

Products
  • Create a Site with WP Engine
  • Shop for Themes
  • Theme Features
  • Get Started
  • Showcase
Company
  • Brand Assets
  • Terms of Service
  • Accptable Usse Policy
  • Privacy Policy
  • Refund Policy
  • Contact Us
Community
  • Find Developers
  • Forums
  • Facebook Group
  • #GenesisWP
  • Showcase
Resources
  • StudioPress Blog
  • Help & Documentation
  • FAQs
  • Code Snippets
  • Affiliates
Connect
  • StudioPress Live
  • StudioPress FM
  • Facebook
  • Twitter
  • Dribbble