Are you a GenerateCustomer?

Do you have an active GP Premium or GenerateBlocks Pro license key?

Create a GenerateSupport account for GeneratePress and GenerateBlocks support in one dedicated place.

Create an account
Already have a GenerateSupport account? Login

Just browsing?

Feel free to browse the forums. Support for our free versions is provided on WordPress.org (GeneratePress, GenerateBlocks).

Want to become a premium user? Learn more below.

Creating a different menu for the blog posts only

  • Hi, I’d like to create a different menu for the blog posts only, with the following characteristics:
    1. if possible, to have different items than the primary menu
    2. if possible, to have different colours than the primary menu
    3. to be integrated in the header – I think it’s something related with the merge option, but I;m not sure how to use it.
    Can someone please explain the exact steps to do so?
    The domain where I’d like to use it is: https://archetypeleadership.com/
    Thanks so much!

  • Hi there,

    Yes, it’s possible with some PHP and CSS code. But do you mean blog page or single posts? The code below is written for the single posts.

    1. Create a new menu at Appearance > Menus.

    2. Add this PHP code:

    add_filter( 'wp_nav_menu_args', function ( $args ) {
        // if the menu is the primary menu && is a single post
        if ( 'primary' === $args['theme_location'] && is_single()  ) {
                $args['menu'] = 'My second menu'; //change it to the actual menu name
        }
        return $args;
    } );

    Adding PHP: https://docs.generatepress.com/article/adding-php/

    Once the menu is implemented, let me know what kind of style you are looking for for the menu.

  • Thanks so much!
    This different menu I’m asking about is meant for a single post – do I need another one if I want it for the blog page?

  • Hi there,

    If you also want to set a specific menu for the blog page, replace the snippet with this one:

    add_filter( 'wp_nav_menu_args', function ( $args ) {
        // if the menu is the primary menu
        if ( 'primary' === $args['theme_location'] ) {
            
            // Different menu for single posts
            if ( is_single() ) {
                $args['menu'] = 'My second menu'; // Menu for single posts
            }
            
            // Different menu for blog page
            if ( is_home() ) {
                $args['menu'] = 'Blog menu'; // Menu for blog page - change to your actual menu name
            }
        }
        return $args;
    } );
  • Thanks! So, where do I insert this code, please? And how can I style the different menus?

  • So, where do I insert this code, please?

    You can use one of the methods mentioned in this article:
    Adding PHP: https://docs.generatepress.com/article/adding-php/

    And how can I style the different menus?

    Can you clarify what specific styles you’d like to apply?

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.