Site logo

Archived topic

Formatting Meta Data On Single Blog Posts and Pages

5 replies · Started by Nicola on November 4, 2020

Viewing posts 1–6 of 6

Hello! I'd like to customize the metadata on the top of my blog posts and pages.

I have GeneratePress Premium and I'm using the "Target" Demo. As it is now, blog posts are displaying the title and date at the top of the post, and the category and tag at the bottom of the post below the content. I have added a hook with an affiliate disclosure that is also displaying at the top of the post.

I would like to have all of the metadata (title, date, category, and tag) as well as the affiliate disclosure, at the top of the post, between two horizontal lines. How would you recommend doing this?
I sent you a private screenshot of what it looks like now and what I'd like it to look like.
Thanks!

Hi there,

Let's do this one step at a time.

Can you add this PHP snippet first?

add_filter( 'generate_header_entry_meta_items', function() {
    return array(
        'categories',
        'tags',
        'date',
    );
} );

Adding PHP: https://docs.generatepress.com/article/adding-php/

Please do disable the maintenance mode while we are helping.

Thanks!

Great! I have done this and I took the site out of maintenance mode. It's showing the metadata at the top as requested, but I would love to have some kind of divider between each entry. So it reads: Category | Tag | Date

Thank you!

Hi there,

now add this snippet to insert a pipe | before the tags and date:

add_filter( 'generate_inside_post_meta_item_output', function( $output, $item ) {
	if ( 'tags' === $item || 'date' === $item ) {
        return ' | ';
    }
    return $output;
}, 50, 2 );

Amazing, that worked great! Thank you!

Glad we could be of help

This archived topic is closed to new replies.