--> How To Show Author Image Next To Post Title In Genesis? | Experience Lab - Online business creation and development guide for bloggers and startups

How To Show Author Image Next To Post Title In Genesis?

The Genesis Framework , as many of you might know, is the most popular framework for WordPress, and indeed one of the most powerful ones. It...



How To Show Author Image Next To Post Title in Genesis

The Genesis Framework, as many of you might know, is the most popular framework for WordPress, and indeed one of the most powerful ones. It allows you to build a customized websites, and make use of the many action and filter hooks inherently present, on top of the default WordPress ones. We ourselves are using the framework on two of our sister blogs. So we thought our readers might like a few genesis tutorials. In this post, we'll talk about how to add an author avatar next to post titles on home page, category pages, and post pages on a WordPress Blog.


WordPress Hooks



At the core of a WordPress blog lie Hooks. And there are two types of hooks; Action hooks, and Filter hooks. Now their detail will be left to another post, but for now, let's take a look at the basic overview of Actions and Filters.




Hooks enable us to literally hook into parts of a WordPress page when it is loading, so that we can add, delete or modify data and take certain actions behind the scenes before the final page is displayed to a reader. There are two types of hooks; action and filter hooks.




Actions are events that occur on a WordPress page - for example, certain resources loading, certain facilities becoming available, etc. Action hooks allow us to add or delete certain events. Filter hooks allow us to modify events.




For example, on a typical WordPress blog homepage, you see a list of some of the latest posts. Things like the post titles, featured images, excerpts etc loading are events. But if I were to convert all the words in the post titles to upper-case, then I'd have to use a filter hook. Similarly, an action hook will let us display a list of our posts (when designing a custom theme), but a filter hook will be used to alphabetically sort those posts (instead of the default WordPress sorting by date).


Adding author avatar to post title



Now that you have a basic understanding of WordPress Hooks, we can now add an author avatar using hooks. Almost all the theme customization in WordPress is done via action and filter hooks. Now you can add the avatar using actions as well as filters. Let's take a look at each in turn.


Note: For the purpose of this tutorial, you will have edit a theme file. So it is best that you keep a backup in case something goes wrong. The file in question is the functions.php  file, which you can find by going into Appearance from your WordPress dashboard, and then clicking on the Editor. You can then select the functions.php file from the sidebar on the right.


Using the action hook



We will first create a function to display author avatar, and we'll then plug that function into a hook. See the code below.




function custom_post_author_avatars () {

   echo '<div style="float:right">'

      . get_avatar (get_the_author_id (), 40)

      . '</div>';

}

add_action ('genesis_before_post_title', 'custom_post_author_avatars');




The function name 'custom_post_author_avatars' can be changed to anything, but make sure it is something unique, because you'll get a lot of errors if another default function of the same name already exists.




You can change the style for the div tag that encloses the image. I've set it to float right, so that my image will display on the right side of the post. You can float it left, and then apply some margin or add a border and padding, or whatever you fancy.




get_avatar is a pre-defined function, and so is get_the_author_id (). Make sure you don't change them.




genesis_before_post_title is an action hook that executes right before a post's title is displayed. You can use similar hooks such as genesis_after_post_title, genesis_post_title, and genesis_before_content for a similar effect (but with varying image placement of course). See here for a full list of genesis hooks you can hook into and add an action.


Final thoughts



You can achieve the same task by removing the genesis_do_post_title function from the genesis_post_title hook, and then using the same hook to add your own custom function that displays post title enclosed in a H2 tag, along with the author avatar. Another possible way to do is to add your custom function to the filter genesis_post_title_output, and in that function, displaying the post title text, along with the image.




All these methods work fine, but they're not efficient, and are definitely not the best way to do the job. Therefore, you can simply hook a custom function of your own to the genesis_before_post_title hook, like I did in this tutorial, and get the job done!




I know this might be confusing for some of you, but I am here to help! Just feel free to ask in the comments section below. Cheers :)

COMMENTS

Name

Affiliate Marketing,12,Announcement,34,Bing,9,Bitcoin,38,blog,7,Blogger Resources,42,Blogger Templates,4,blogger tricks,156,Blogging ethics,70,Blogging tips,198,Bugs and Errors,34,Business,9,Copyright Violation,9,CSS and HTMLTricks,95,Designs,8,drop down menu,7,eBook,12,Email Marketing,7,Events,30,Facebook,30,Facebook tricks,49,Google,157,Google AdSense,42,Google Analytics,7,Google Plus,51,Google Plus Tricks,38,Guest Posts,112,home,2,How To,77,Internet,1,JSON Feeds,25,Kitchen Recipes,2,Label Based Sitemap Themes,1,Make Money Online,108,Marketing,16,MBT Blogger Templates,7,Menus,1,News,146,Pages,1,Posts,10,presentations,15,Responsive,10,Reviews,7,SEO,307,Settings,6,Shortcode,15,Sitemap Themes,1,Social Media,155,Technology,7,Templates,1,Tips,2,Tools,1,Traffic Tips,80,Video,19,Web Designing,62,web hosting,18,Webmaster Tools,97,Widgets,199,wordpress,26,
ltr
item
Experience Lab - Online business creation and development guide for bloggers and startups: How To Show Author Image Next To Post Title In Genesis?
How To Show Author Image Next To Post Title In Genesis?
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjDgttjpCOk30GpSaRS-tJR_3koIW3HL0iTc-3S51p7Dy-KtRZWQ-ME2TtuVK3pt77HuarSGTbh0zrjCakISwLW6Yy1O76K6Ets8MxseTGYy784ykc5GNvJYLFjHuicIQHxkZJ86zqvLHEw/s320/display-author-image-next-to-post-title.jpg
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjDgttjpCOk30GpSaRS-tJR_3koIW3HL0iTc-3S51p7Dy-KtRZWQ-ME2TtuVK3pt77HuarSGTbh0zrjCakISwLW6Yy1O76K6Ets8MxseTGYy784ykc5GNvJYLFjHuicIQHxkZJ86zqvLHEw/s72-c/display-author-image-next-to-post-title.jpg
Experience Lab - Online business creation and development guide for bloggers and startups
https://www.experiencelab.info/2013/10/how-to-show-author-image-next-to-post.html
https://www.experiencelab.info/
https://www.experiencelab.info/
https://www.experiencelab.info/2013/10/how-to-show-author-image-next-to-post.html
true
2959477579779989044
UTF-8
Loaded All Posts Not found any posts VIEW ALL Readmore Reply Cancel reply Delete By Home PAGES POSTS View All RECOMMENDED FOR YOU LABEL ARCHIVE SEARCH ALL POSTS Not found any post match with your request Back Home Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sun Mon Tue Wed Thu Fri Sat January February March April May June July August September October November December Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec just now 1 minute ago $$1$$ minutes ago 1 hour ago $$1$$ hours ago Yesterday $$1$$ days ago $$1$$ weeks ago more than 5 weeks ago Followers Follow THIS PREMIUM CONTENT IS LOCKED STEP 1: Share. STEP 2: Click the link you shared to unlock Copy All Code Select All Code All codes were copied to your clipboard Can not copy the codes / texts, please press [CTRL]+[C] (or CMD+C with Mac) to copy