0

I am trying to convert this piece of code into a shortcode so it can be used inside my posts. Is it possible? I cant think of how to do it as I am beginner in wordpress and learning via books/youtube and wordpress documentation.

The code is:

    global $userpro;
$userpro->permalink( get_the_author_meta('ID') );

The goal is to have that be executed in the post as [authorlink]

If it isnt possible to do so can I add the above code inside the single post template and show it at a specific spot using if so how could this be done?

Thank you all for your contributions.

2 Answers 2

0
add_shortcode('userpro_author_link', 'wpse_152910');
function wpse_152910( $attr ){
    if( ! is_singular() )
        return '';

    $post = get_post();
    global $userpro;
    $userpro->permalink( $post->post_author );
}

You will be using [userpro_author_link] on your post content to display this.

0
0

Sounds like it might be easiest to slide some php right it into single.php, so it always displays and you don't have to worry about it.

<?php
  echo '<a href="'.get_author_posts_url(get_the_author_meta('ID')).'">'.get_the_author_meta( 'display_name').'</a>';
?>
1
  • Thank you for your reply, I cant upvote your reply yet due to my level. I have trouble possitioning the output of the echo when I paste it in single.php thats why I thought to go for shortcode as it can be pasted anywhere inside the post but with the disadvantage of always having to paste it instead of automatically being added like when in single.php. Commented Jul 7, 2014 at 22:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.