Site logo

Archived topic

Flip date and author

1 reply · Started by Matthew on December 21, 2022

Viewing posts 1–2 of 2

How do I change the location of the date and author in a single post?

https://imgur.com/6QSljF0

Ideally, I would like the author name (By xxx) to be the first thing displayed, followed by the date, separated by a "|"

Example, it would read:

By: John Doe | February 31, 2032

Hi Matthew,

Try adding this Snippet:

add_filter( 'generate_header_entry_meta_items', function( $items ) {

    if ( is_single() ) {
        return array( 'author', 'date' );
    }
	return $items;
    
} );

add_filter( 'generate_post_author_output', 'tu_modify_by_byline' );
function tu_modify_by_byline() {
	printf( ' <span class="byline">By: %1$s</span>', // WPCS: XSS ok, sanitization ok.
		sprintf( '<span class="author vcard" itemtype="https://schema.org/Person" itemscope="itemscope" itemprop="author"><a class="url fn n" href="%1$s" title="%2$s" rel="author" itemprop="url"><span class="author-name" itemprop="name">%3$s</span></a></span>',
			esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
			/* translators: 1: Author name */
			esc_attr( sprintf( __( 'View all posts by %s', 'generatepress' ), get_the_author() ) ),
			esc_html( get_the_author() )
		)
	);
}

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

Then, add this through Appearance > Customize > Additional CSS:

.single-post .entry-meta .byline:after {
    content: " | ";
}
This archived topic is closed to new replies.