I’ve been trawling through forums but can’t find a solution to this. If anyone can help, it would be greatly appreciated!
I’m trying to display a link to current users author page (all users have author permissions).
I’m using this at the moment:
<a href="<?php echo home_url() . '/author/' . get_the_author_meta( 'user_login', wp_get_current_user()->ID ); ?>" >My personal page</a>
The problem is, the author link displays when there is no user logged in. How can I only display the author link to users that are logged in?
Well if your code is working properly and the only problem is that it displays when no one is logged in then try the code below. Because right now you are saying “Hey WP just echo out this” – so it does it. You need to change it to: “Hey WP if the user is logged in show the link to his page and if not show the login link” like that:
Now to address the problem with user names with spaces you could try this code:
Reference:
@user45381 You must use
get_author_posts_url
along withis_user_logged_in
to fetch the authors page.You can use the below to get this done:–