[Support request] Two or more categories for one post menu effect

Home Forums Support [Support request] Two or more categories for one post menu effect

Home Forums Support Two or more categories for one post menu effect

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #625950
    Salvador

    Hi,
    I have the following problem …

    I want my posts to have different categories, and that the categories are in the menu. The problem is that this implies that when viewing the post, all the categories change their effect in the menu.

    How could I solve it?


    Only one category


    many categories

    #625977
    Leo
    Staff
    Customer Support

    Hi there,

    You can try using Custom Link for menu item and add the link to the category page as the URL:
    https://docs.generatepress.com/article/using-the-wordpress-menu-builder/#custom-link

    #625990
    Salvador

    Hi Leo,

    Thanks for your quick reply.

    Yes, what you comment works … half.

    They no longer ‘highlight’ or change the color of the menu categories … but my intention was to know if there was any way to select a category ‘main’ for the post (if you have several) to continue making the effect .

    Is there any other way?

    Thanks.

    #625994
    Leo
    Staff
    Customer Support

    I think you will have to try something like this:
    https://joshuawinn.com/using-yoasts-primary-category-in-wordpress-theme/

    Untested so I’m not sure if this will work for the menu items also. Worth a shot though.

    #626005
    Salvador

    I just tried, both with Yoast SEO and another SEO plugin, but it has not worked.

    I guess it’s something impossible ๐Ÿ™

    #626103
    Leo
    Staff
    Customer Support

    I don’t think so but I’ll check with Tom ๐Ÿ™‚

    #626220
    Tom
    Lead Developer
    Lead Developer

    You could maybe try something like this:

    add_filter( 'nav_menu_css_class', 'my_special_nav_class', 10, 2 );
    function my_special_nav_class( $classes, $item ) {
        $posts_to_watch = array(
            'A Single Post Title',
            'Another Post Title',
            'One More Post Title',
        );
    
        foreach ( $posts_to_watch as $post ) {
            if ( is_single( $post ) && $post === $item->title ) {
                $classes[] = 'current-menu-item';
            }
        }
    
        return $classes;
    }

    So you’d have to:

    1. Keep using custom links where nothing gets highlighted.
    2. Update the array of $posts_to_watch with the titles of your posts you want to highlight.

    Just a theory – I haven’t tested it.

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