Let People Know The Author

Let People Know The Author

If your WordPress website has a blog you probably ever wondered how to display the author of the post. Of course, you simply may finish a blog article with a name of a person who composed it to identify the author. But I know the way to be saved from routine and to publish the author name automatically.

WordPress provides many functions to be used to simplify our work on website creation, but people who uses WordPress don't have any code editing experience in most cases. However, some themes for WordPress are aimed to expand your capabilities as well as SMThemes.

All these themes are served with this option, but today I will tell you what you have to do if this option is not provided. In addition the information below will be much helpful for those who wants to edit the existing option provided by SMThemes.

Which Code Is Necessary To Display Author

As I already told many times WordPress is a great platform. It has already lots of things you need so much. You just have to use them. The same things happen here with author information.

There are several simple code lines which could help you. The easiest one is:

<?php echo get_the_author(); ?>

Could you imagine that this is all that you are needed? Yeah, that's it!

In addition to this code line one more can be very helpful in some cases:

<?php get_the_author_meta( 'ID' ); ?>

Before this function has to be retrieved if you call the first one, because it returns author ID. It was obligatory to specify as parameter of the get_the_author() function, then became optional and now it is deprecated. But I wanted to mention it because its benefit is obvious if you look a bit further.

A bit more complicated thing is to display author avatar. This function ( provided by WordPress alike ) have some parameters inside the brackets including author ID, you see?

<?php echo get_avatar( $id_or_email, $size, $default, $alt, $args ); ?>

To identify the person which avatar must be displayed you have to specify his id or email and size of avatar. Now you know how to get it thanks to the previous example ;)

Integrating these two functions you can easily get author avatar:

<?php echo get_avatar( get_the_author_meta( 'ID' ), 60 ); ?>

All the rest parameters are optional and can be specified only if you want. Use the full tutorial for this function in this case.

Find The Loop To Insert The Code

All the posts, pages are displayed in loop in WordPress. There is a special query which calls all the posts in a specific order. So there is always some code looking like:

if ( have_posts() ) : while ( have_posts() ) : the_post();

inside which the all the posts have the same structure. In the themes from SMThemes, this file is called 'loop.php', 'theloop.php' or 'content.php' as well.

So once you found this code the function returning author name can be used here. And you get author ( perhaps, with avatar ) on each post automatically - exactly like I have promised you.

Leave a Reply