How to customize Meta Entry

When you working on a post template or Blog page you always come across with the post tags and post categories.  It is SEO purpose as well, including Meta tag into posts are always recommended. As you can see above this page title, there is my avatar, category, tag, and post date. Let’s take a look at the code. You can also skip one by one step and scroll down to the bottom of the page to check final HTML code.

The avatar

You can reference get_avatar in Function Reference/get avatar.

Technically I’m doing here is get Author ID or Email, size of thumbnails, if there is no thumbnail use default image, print out Author name.

The Author

This is straight forward. Get the Author name and link to the Author page.

Moving on to categories….

The Category

Since I only need the first category I’m doing get_the_category();. If you are looking for a list of secondary categories you need to edit first line to $categories = get_categories( array( 'child_of' => 10 );  see get_categories in Codex.

I like to wrap the code with variable is not empty. if ( ! empty( $categories ) ) {...} It is useful when you have spacing or padding to the element. In this case, if there is no category selected the category icon does not show either. Sweet!

Always use esc_url when sanitizing URLs and esc_html to escaping for HTML blocks. This is recommend in Codex.

The Tags

Again I’m wrapping my code with if ( ! empty( $posttags ) ) {...}  so if there is no tags it doesn’t show Tag icon.

I added rtrim($taglist, ", "); to remove comma from last tag item.

The Post Date

For the formatting of date and time you can reference Formatting Date and Time.

This is it. Now you can add style or change the orders to match your design.