Please try with this-
/*
*
* Shortcode to display Post as links on Profile Pages
*
*/
function imwz_golfs_list_function( $atts ) {
if ( is_user_logged_in() ):
global $current_user;
wp_get_current_user();
$author_query = array('posts_per_page' => '-1','author' => $current_user->ID);
$author_posts = new WP_Query($author_query);
ob_start();
if($author_posts->have_posts()) :
echo '<ul>';
while($author_posts->have_posts()) : $author_posts->the_post();
?>
<li><a href="https://wordpress.stackexchange.com/questions/295515/<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></li>
<?php
endwhile;
echo '</ul>';
else :
echo "not logged in";
endif;
$content = ob_get_clean();
return $content;
endif;
}
add_shortcode( 'golfslist', 'imwz_golfs_list_function' );
Not tested, but should work.
Please note, your content should be “returned”, not “echoed” while using for shortcode.