Last Updated on May 4, 2017
Filed under Dev

Blog Post Meta Display

When displaying blog post either using the page templates, or shortcodes, meta is used to display the author, date, categories, and number of comments. For the most part, the default layout of this information is completely fine; however, you may want to remove, alter or even duplicate/move the meta into other areas of the post. With that, you have to filters that can aid in displaying this data.

  • bne_meta_separator()
  • bne_meta_order()
  • bne_meta_output()

Let's take a look at each one...

bne_meta_separator() - (A) this filter returns the markup used to display a "/" between each meta information. The html is optional in the return but is already formatted for spacing. The below example changes "/" to "X".

bne_meta_order() - (B) this filter returns an array of the what should display and the order of meta. The default pattern is the date, author, category, and comments. With this filter, you could reverse it or remove parts of it. To only display the date, you would return date. To return only the author and date in that order you would return author_date or as an array, array( 'author','date').

Let's look at just returning the order. The below example shows different ways of returning the meta order. This allows you to also conditionally return it based on the page, user role, etc.

You'll also notice the 2nd argument, $location. There are two locations in on a single post where meta is shown, on top below the title and on the bottom before the comments. To target only the meta at the top, you would assign the location to "header" and on the bottom, "footer".

bne_meta_output() - this filter is a catch all filter and allows you to completely change what is returned including customizing the actual meta information.

For an example using this filter, we're going to change how the meta is displayed in the header by only displaying the author and date, but include additional text.

The actual output function

In the end the actual display of the post meta is handled using bne_post_meta(). This function is found on content-single.php and the post list and grid templates. If you're planning to throw these files into a child theme, you can actually alter what is returned there as well. It accepts the following arguments:

  • $sep (string) - The character / symbol used between each meta piece
  • $return (array) - The meta to return and the order it's in.
  • $location (string) - The location within the post.

A use for this is if you're customizing the single display heavily and want to show the date, author, and comments into completely different areas and separated from each other. You can by telling the function to only return what you need.

echo bne_post_meta( null, 'author' );