I have several author page like
mysite/author/username1
mysite/author/username2
I want to create a dynamic url like
mysite/author/current_loggedin_username
How to create this.
I have several author page like
mysite/author/username1
mysite/author/username2
I want to create a dynamic url like
mysite/author/current_loggedin_username
How to create this.
Share Improve this question edited Aug 3, 2019 at 15:18 nmr 4,5672 gold badges17 silver badges25 bronze badges asked Aug 3, 2019 at 15:05 user172955user172955 32 bronze badges 2- Can you provide more details? Currently, it is not clear to me what is going on with this dynamic link. – nmr Commented Aug 3, 2019 at 15:27
- @nmr I want to create an author page link in navigation menu bar where the logged in user will get to see all his post. The author page link is in this format mysite/author/{logged_in_username} .I want to pass the username in the url – user172955 Commented Aug 3, 2019 at 15:32
1 Answer
Reset to default 0First, you should check if the user is logged in - use is_user_logged_in().
Next step is to get ID of current user with get_current_user_id().
Next, get the URL for the author with the given ID using get_author_posts_url().
The last step is to display the button with the link.
if ( is_user_logged_in() )
{
$uid = get_current_user_id();
$link = get_author_posts_url( $uid );
printf( '<div><a href="%s">My posts</a></div>', $link );
}
You can insert such a code in the header.php
file or add it as a function to functions.php
file and call this function in the header.php
.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745273074a4619869.html
评论列表(0条)