[Resolved] Current author archive in navigation menu

Home Forums Support [Resolved] Current author archive in navigation menu

Home Forums Support Current author archive in navigation menu

Viewing 14 posts - 1 through 14 (of 14 total)
  • Author
    Posts
  • #663775
    Feri

    Hi,

    Based on this tutorial LINK

    function my_nav_menu_author_link( $menu )
    {
        if( !is_user_logged_in() ){
    
            return $menu;
    
        } else {
    
            $link = get_author_posts_url( get_current_user_id() );
    
            $class = is_author() ? ' class="current-menu-item"' : '';
    
            $author_archive_link = 
            '<li' . $class . '>' .
                 '<a href="' . $link . '" >' .
                     __( 'My posts' ) .
                 '</a>' .
             '</li>';
    
            $menu = $menu . $author_archive_link;
    
            return $menu;
    
        }
    }
    
    add_filter( 'wp_nav_menu_items', 'my_nav_menu_author_link' );

    i already success to make author archive link at navigation menu. screenshot: image default location is always at the right corner navigation menu. its not flexible.

    i want to make that author menus link to become Sub menu for another link menu. Something Like: ACCOUNT – AUTHOR MENU etc

    the problem is that author menus only show at front end without another setting at Menus Structure (Appearance – Menus)

    Need your help..

    Thank You

    #663826
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    Have you considered using a plugin like this?: https://wordpress.org/plugins/nav-menu-roles/

    Let me know πŸ™‚

    #663831
    Feri

    Hi,

    Sorry for my bad explanation, but this is not about navigation menu role.

    I just want to add author post link to the nav menu. Something like “Login Logout Link” Nav Menus but for “Author Post Link”.

    The Author link is work actually but i can not setting the position to another menus place (sub menus, etc)

    #663833
    Tom
    Lead Developer
    Lead Developer

    Ah, my mistake!

    I’m not sure if you can dynamically insert a link as a sub-menu unfortunately.

    What you could do is use the plugin I suggested to show the menu item only for logged in users. That way you can add a custom link as a sub-menu item.

    Then you can use a plugin like this to insert a shortcode as the custom link URL: https://wordpress.org/plugins/shortcode-in-menus/

    Then create a shortcode for the URL:

    add_shortcode( 'author_url', function() {
        return get_author_posts_url( get_current_user_id() );
    } );
    #663853
    Feri

    yes perfect! it work…

    but, previously i have another plugin for Nav Menu Role, the plugin is “If Menu – Visibility control for Menu Items”. Both of great plugin, btw…

    one question again, how to prevent 404 of Author pages without posts? when i click Author Link Menus (without post) suddenly directed to 404 pages.

    is possible to customise the author page without post become someting like “No Post bla bla”?

    #664598
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    Is it a 404 page, or a no results page? Can you link me to an example?

    #664828
    Feri

    sorry my mistake, its not 404 but no result/nothing found page. so i think the problem is solved.

    but at the end of the page author (without post) there is “Load More” button. how to remove it?

    screenshot: Load More Button

    thank you so much for your help and support.

    #664920
    Tom
    Lead Developer
    Lead Developer

    That definitely shouldn’t be there. Just to confirm that you’re using GPP 1.7.2?

    #664925
    Feri

    Hi,

    Yes, GP Premium 1.7.2.

    Just sent you an email about the link to the profile author page.

    thank you…

    #665422
    Tom
    Lead Developer
    Lead Developer

    Looks like a bug.

    For now, use this CSS:

    .no-results + .load-more {
        display: none;
    }
    #665630
    Feri

    thank you so much, Tom.

    #665645
    Tom
    Lead Developer
    Lead Developer

    No problem! πŸ™‚

    #1554124
    Zach

    This suggestion isn’t working: https://wordpress.stackexchange.com/questions/378971/adding-author-url-to-nav-menu-via-shortcode

    Basically, when you use that plugin with your shortcode the output is either plain text or if you put the shortcode in the custom link field it creates a url that looks like this: http://https://mysite.local

    How do you stop it from outputting the extra http?

    #1555160
    Leo
    Staff
    Customer Support

    That looks like a plugin’s issue and not a theme issue.

    However it seems to work for the topic author though.

    Can you open a new topic for your question first?

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