Site logo

[Support request] Flip date and author

Home Forums Support [Support request] Flip date and author

Home Forums Support Flip date and author

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #2470019
    Matthew

    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

    #2470027
    Fernando
    Customer Support

    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: " | ";
    }
Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.