{"id":67334,"date":"2011-12-22T09:00:50","date_gmt":"2011-12-22T14:00:50","guid":{"rendered":"http:\/\/wpmu.org\/?p=67334"},"modified":"2017-05-25T07:26:52","modified_gmt":"2017-05-25T07:26:52","slug":"tutorial-how-to-add-authors-images-to-your-wordpress-blog","status":"publish","type":"post","link":"https:\/\/wpmudev.com\/blog\/tutorial-how-to-add-authors-images-to-your-wordpress-blog\/","title":{"rendered":"How to Add Author Images to Your WordPress Blog"},"content":{"rendered":"<p>Have you ever wished you could display the photos of your site\u2019s authors (i.e. their avatars) in a more creative way, such as showing the author\u2019s avatar right beside the headline of each post?<\/p>\n<p>Well, you can. It\u2019s actually not that hard. It just takes placing a few lines of code in your theme.<\/p>\n<h2><strong>Uploading an Avatar<\/strong><\/h2>\n<p>Before we get into the code to do this, you should make sure that you have uploaded an avatar. WordPress default doesn\u2019t have a place to upload avatars, but you can get a plugin that will do that, or probably the easiest solution is to go to <a href=\"http:\/\/www.gravater.com\" rel=\"noopener\" target=\"_blank\">gravatar.com<\/a> and upload an avatar there.<\/p>\n<p>The email address you use at\u00a0gravatar.com should be the same email address you use as your registration address in your WordPress site. (By the way, the avatar you upload at gravatar.com will follow you around the web as long as you are using that same email address. There are many sites that will recognize your Gravatar avatar.)<\/p>\n<h2><strong>The Code to Display Avatars \/ Profile Pictures<\/strong><\/h2>\n<p>There are a number of different pieces of code you could use to display your avatar in WordPress. Here is the one we will use for this example:<\/p>\n<p><code>&lt;?php echo get_avatar( get_the_author_meta('ID'), 60); ?&gt;<\/code><\/p>\n<p>In this case, the number you see there (60) is the size of the avatar. You can simply make that bigger or smaller to suit your needs.<\/p>\n<h2><strong>Avatar Appears, but without Style<\/strong><\/h2>\n<p>If you insert the code above into your theme (for example in your single.php file), you should see the photo of that post\u2019s author. The only problem with this is that it simply puts the photo wherever you\u2019ve put the line of code without controlling it in any way.<\/p>\n<p><a><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-67336\" src=\"https:\/\/wpmudev.com\/blog\/wp-content\/uploads\/2011\/12\/avatar-not-styled.jpg\" alt=\"Post image\" aria-hidden=\"true\" width=\"628\" height=\"631\" \/><\/a> <\/p>\n<h2><strong>Controlling the Avatar with Styling<\/strong><\/h2>\n<p>In order to get the photo to line up in a way that looks better, we are going to need to style it with some CSS styling.<\/p>\n<p>In order to do that, first we are going to need to put it in a unique \u201cdiv\u201d \u2013 i.e. its own division, its own section. Here\u2019s a way we can do that.<\/p>\n<p><code>&lt;div id=\"author_pic\"&gt;<br \/>\n&lt;?php echo get_avatar( get_the_author_meta('ID'), 60); ?&gt;<br \/>\n&lt;\/div&gt;<\/code><\/p>\n<p>This creates a new division\/section called \u201cauthor_pic\u201d that is unique.<\/p>\n<p><strong>Important:<\/strong> Make sure your new div is unique. It should <strong>NOT<\/strong> have the same name as another div in your theme.<\/p>\n<p>So we now have our div set up, but we still need to style it. We do that by referencing the div we\u2019ve just created (\u201cauthor_pic\u201d) in the Stylesheet (style.css).<\/p>\n<p><strong>CSS Stylesheet<\/strong><\/p>\n<p>In the style sheet (Appearance &gt; Edit &gt; Stylesheet (style.css)), we\u2019ll control the div with the style we want. Here\u2019s an example.<\/p>\n<p><code>#author_pic {<br \/>\nfloat: left;<br \/>\nmargin-right: 10px;<br \/>\n}<\/code><\/p>\n<p>First we name it the same as we named the div, but we put a hash tag in front of it first. And we also put the opening bracket.<\/p>\n<p><code>#author_pic {<\/code><\/p>\n<p>Then we tell it we want it aligned to the left.<\/p>\n<p><code>float: left;<\/code><\/p>\n<p>And then, because it\u2019s going to be aligned to the left and therefore is going to have the content (in this case the title and the date) to the right of it, we need to make sure it doesn\u2019t run together as it did originally. And so we are going to say, \u201cGive me a 10 pixel margin on the right-hand side.\u201d \u2026 And we\u2019ll go ahead and put in the closing bracket.<\/p>\n<p><code>margin-right: 10px;<br \/>\n}<\/code><\/p>\n<p>Now that we\u2019ve controlled the div with CSS, here\u2019s what we get.<\/p>\n<p><a rel=\"lightbox[67334]\" class=\"blog-thumbnail\" href=\"https:\/\/wpmudev.com\/blog\/tutorial-how-to-add-authors-images-to-your-wordpress-blog\/automatically-inserted-beside-headline\/\" rel=\"attachment wp-att-67337\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-67337\" src=\"https:\/\/wpmudev.com\/blog\/wp-content\/uploads\/2011\/12\/automatically-inserted-beside-headline.jpg\" alt=\"Post image\" aria-hidden=\"true\" width=\"647\" height=\"665\" \/><\/a><\/p>\n\n<h2><strong>Linking to Author\u2019s Posts<\/strong><\/h2>\n<p>So all of that is looking pretty good. But the avatar that gets inserted is just photo, and that\u2019s it. Many people will probably try to click on the photo thinking they will get more posts from the author or more info about the author.<\/p>\n<p>So let\u2019s go ahead and add a link to the photo that goes to an archive of the author\u2019s other posts.<\/p>\n<p>Our styling is fine, so we don\u2019t need to touch that. But we\u2019re going to need to add more to the code we first inserted.<\/p>\n<p>To make a long story short, let\u2019s just jump to the whole snippet of code.<br \/>\n<code><br \/>\n&lt;div id=\"author_pic\"&gt;<br \/>\n&lt;a href=\"&lt;?php echo get_author_posts_url( get_the_author_meta( 'ID' ) ); ?&gt;\" rel=\"author\"&gt;<br \/>\n&lt;?php echo get_avatar( get_the_author_meta('ID'), 60); ?&gt;&lt;\/a&gt;<br \/>\n&lt;\/div&gt;<br \/>\n<\/code><br \/>\nWhen we do that, clicking on the photo takes the viewer to the author\u2019s archive page, as we hoped.<\/p>\n<p><a rel=\"lightbox[67334]\" class=\"blog-thumbnail\" href=\"https:\/\/wpmudev.com\/blog\/tutorial-how-to-add-authors-images-to-your-wordpress-blog\/links-to-authors-posts\/\" rel=\"attachment wp-att-67338\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-67338\" src=\"https:\/\/wpmudev.com\/blog\/wp-content\/uploads\/2011\/12\/links-to-authors-posts.jpg\" alt=\"Post image\" aria-hidden=\"true\" width=\"647\" height=\"665\" \/><\/a><br \/>\n<\/p>\n<h2><strong>Inserting the Photo in Other Places<\/strong><\/h2>\n<p>Where you insert the author\u2019s avatar is up to you, but we\u2019ll run through one more example that some may like to use.<\/p>\n<p>This time we\u2019ll put the avatar at the top of the sidebar. (Appearance &gt; Editor &gt; Sidebar) We\u2019ll also go ahead and keep it linked to the author\u2019s archive page.<\/p>\n<p><code>&lt;a href=\"&lt;?php echo get_author_posts_url( get_the_author_meta( 'ID' ) ); ?&gt;\" rel=\"author\"&gt;<br \/>\n&lt;?php echo get_avatar( get_the_author_meta('ID'), 198); ?&gt;&lt;\/a&gt;<\/code><\/p>\n<p><a rel=\"lightbox[67334]\" class=\"blog-thumbnail\" href=\"https:\/\/wpmudev.com\/blog\/tutorial-how-to-add-authors-images-to-your-wordpress-blog\/code-in-sidebar\/\" rel=\"attachment wp-att-67339\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-67339\" src=\"https:\/\/wpmudev.com\/blog\/wp-content\/uploads\/2011\/12\/code-in-sidebar.jpg\" alt=\"Post image\" aria-hidden=\"true\" width=\"628\" height=\"366\" \/><\/a><br \/>\nYou\u2019ll notice that this is basically the same code as before, but two things are different. The first is that the divs are gone. The reason for this is that the space in the sidebar is so confined, that there isn\u2019t really anywhere for the photo to go (at least not the way I\u2019m using it).<\/p>\n<p>The second thing is I\u2019ve change the pixels from \u201c60\u201d to \u201c198.\u201d I decided that I wanted a large photo to go right at the top of the sidebar, and I wanted it to basically take up the whole space. (Your size may be different, of course, according to your theme.)<\/p>\n<p>And here\u2019s the result.<\/p>\n<p><a rel=\"lightbox[67334]\" class=\"blog-thumbnail\" href=\"https:\/\/wpmudev.com\/blog\/tutorial-how-to-add-authors-images-to-your-wordpress-blog\/sidebar-3\/\" rel=\"attachment wp-att-67340\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-67340\" src=\"https:\/\/wpmudev.com\/blog\/wp-content\/uploads\/2011\/12\/sidebar.jpg\" alt=\"Post image\" aria-hidden=\"true\" width=\"647\" height=\"665\" \/><\/a><\/p>\n<h2><strong>Style as You Like<\/strong><\/h2>\n<p>These two basic examples should be enough to get you going. And of course there is a lot more you could do with this if you have the CSS know-how. Just remember that you will need to go in an add the code to whichever files you want the avatars to show up in.<\/p>\n<p>Play around with it. It can really add a professional looking touch to your site.<br \/>\n<\/p>\n<p>Photo: <a href=\"http:\/\/www.bigstockphoto.com\/image-3754107\/stock-photo-author-icon-or-symbol\" target=\"_blank\">Author Icon Or Symbol<\/a> from BigStock<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Automatically insert an author\u2019s picture into various spots on your site.<\/p>\n","protected":false},"author":84404,"featured_media":67343,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"blog_reading_time":"","wds_primary_category":0,"wds_primary_tutorials_categories":0,"footnotes":""},"categories":[263],"tags":[640,80,16],"tutorials_categories":[],"class_list":["post-67334","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tutorials","tag-authors","tag-avatars","tag-images"],"_links":{"self":[{"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/posts\/67334","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/users\/84404"}],"replies":[{"embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/comments?post=67334"}],"version-history":[{"count":3,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/posts\/67334\/revisions"}],"predecessor-version":[{"id":165376,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/posts\/67334\/revisions\/165376"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/media\/67343"}],"wp:attachment":[{"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/media?parent=67334"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/categories?post=67334"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/tags?post=67334"},{"taxonomy":"tutorials_categories","embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/tutorials_categories?post=67334"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}