Site logo

Archived topic

Current author archive in navigation menu

13 replies · Started by Feri on August 29, 2018

Viewing posts 1–14 of 14

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

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)

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() );
} );

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"?

Hi there,

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

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.

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

Hi,

Yes, GP Premium 1.7.2.

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

thank you...

Looks like a bug.

For now, use this CSS:

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

thank you so much, Tom.

No problem! :)

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?

This archived topic is closed to new replies.