Yep. This is true and you might be here because you’d like a solution. Look no further. I wanted to move my post info section outside the loop for my new theme, but when I discovered the post_author_posts_link
short code wasn’t working, I had to devise a new short code that would. Here’s what you need to do.
Step One
Add the following code to your theme’s functions.php file. For Flint users, this would go in your skin’s functions.php file. This creates a new short code with the ability to get the author’s name and posts archive URL and we assume we’ll be on a single page when this executes.
add_shortcode( 'my_author_posts_link', 'my_post_author_posts_link_shortcode' ); function my_post_author_posts_link_shortcode( $atts ) { global $post, $wp_query; $author_id = $wp_query->posts[0]->post_author; $defaults = array( 'after' => '', 'before' => '', ); $atts = shortcode_atts( $defaults, $atts ); $author = sprintf( '%s', get_author_posts_url( get_the_author_meta( 'ID' ) ), get_the_author_meta('display_name', $author_id), get_the_author_meta('display_name', $author_id) ); $output = sprintf( ' ', $author, $atts['before'], $atts['after'] ); return apply_filters( 'my_post_author_posts_link_shortcode', $output, $atts ); }
Step Two
Now you’re ready to use your new and improved short code wherever you need it. If you use a plugin like Simple Edits, instead of using the Genesis post_author_posts_link
you’ll use your new short code: my_author_posts_link
. Be sure to wrap it in brackets too [ ] — I left them out so they wouldn’t fire on the page ;)
Get My Plugin
I’ve created a plugin that will enable this short code if you prefer to use plugins. It’s super light-weight and will remain in effect no matter which theme you activate. Author Posts Link Shortcode for Outside The Loop