How to link current user to their author page through shortcodes
I need a shortcode to link the current logged in user to their author page but I couldn’t make the function workable. Found this code based on another similar question here:
<?php
if ( is_user_logged_in() ) {
echo '<a href="' . home_url() . '/author/' . get_the_author_meta( 'user_login', wp_get_current_user()->ID ) . '"> My personal page</a>';
} else {
echo '<a href="' . wp_login_url() . '" title="Login">Login</a>';
}
?>
But it gets “syntax error, unexpected ‘href’ (T_STRING), expecting ‘;'” What is the error here?
I also found this code which doesn’t get an error:
<?php
global $current_user;
get_currentuserinfo();
echo get_author_posts_url($current_user->ID);
?>
But if I put this into a shortcode using add shortcode function, it doesn’t display anything.
This has been asked many times here and I have tried those answers but none worked for me. I’m lost and I’m not an expert coder so any help will do.
Thank you!
Leave an answer