[Resolved] Rearranging the entry meta.

Home Forums Support [Resolved] Rearranging the entry meta.

Home Forums Support Rearranging the entry meta.

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #965394
    Jay

    I’m showing the “updated” post date followed by the post author (“Updated: [date] by [name]”) in my entry meta the exact same way it’s being done here: https://woorkup.com/generatepress-review/

    Now I want to switch the order around, so it becomes…

    By: [name] Updated: [date]

    This seems like it should be pretty simple, but I’m having some trouble making it happen.

    Any help would be appreciated. Thanks!

    #965487
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    Are you using any functions right now to alter the post meta?

    If not, try this PHP:

    add_filter( 'generate_header_entry_meta_items', function() {
        return array(
            'author',
            'date',
        );
    } );
    #965573
    Jay

    Hey Tom, thanks for the quick reply.

    I’m actually using the method described in that article for altering the post meta, which is this…

    if ( ! function_exists( 'generate_posted_on' ) ) :
    /**
     * Prints HTML with meta information for the current post-date/time and author.
     */
    function generate_posted_on() 
    {	
    	$date = apply_filters( 'generate_post_date', true );
    	$author = apply_filters( 'generate_post_author', true );
    	//if ( get_the_time( 'U' ) !== get_the_modified_time( 'U' ) ) 
    		$time_string .= '<time class="updated" datetime="%3$s" itemprop="dateModified">%4$s</time>';
    	$time_string = sprintf( $time_string,
    		esc_attr( get_the_date( 'c' ) ),
    		esc_html( get_the_date() ),
    		esc_attr( get_the_modified_date( 'c' ) ),
    		esc_html( get_the_modified_date() )
    	);
    	
    	// If our date is enabled, show it
    	if ( $date ) :
    		printf( '<span style="float: left; margin-right: 3px;">Updated:</span><span class="posted-on">%1$s</span>',
    			sprintf( '<a href="%1$s" title="%2$s" rel="bookmark">%3$s</a>',
    				esc_url( get_permalink() ),
    				esc_attr( get_the_time() ),
    				$time_string
    			)
    		);
    	endif;
    	
    	// If our author is enabled, show it
    	if ( $author ) :
    		printf( ' <span class="byline">%1$s</span>',
    			sprintf( '<span class="author vcard" itemtype="http://schema.org/Person" itemscope="itemscope" itemprop="author">%1$s <a class="url fn n" href="%2$s" title="%3$s" rel="author" itemprop="url"><span class="author-name" itemprop="name">%4$s</span></a></span>',
    				__( 'by','generatepress'),
    				esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
    				esc_attr( sprintf( __( 'View all posts by %s', 'generatepress' ), get_the_author() ) ),
    				esc_html( get_the_author() )
    			)
    		);
    	endif;
    	
    }
    endif;

    Thanks!

    #966103
    Leo
    Staff
    Customer Support

    You no longer need that long function if you are using the latest theme version.

    Tom’s function should work now 🙂

    #966797
    Jay

    Hmmmm, I’m not sure I understand what you mean?

    I originally began using this long function a while ago to show the updated post date because it was the only method that successfully caused Google to show the updated date for my posts in its results. I tested the CSS method covered in the GP docs, but it didn’t make this happen.

    Has something changed since then?

    Thanks.

    #967125
    Leo
    Staff
    Customer Support

    You can use this to change the HTML markup now:
    https://docs.generatepress.com/article/generate_post_date_output/#only-show-updated-date

    Let me know if this helps 🙂

    #968057
    Jay

    Ahhh, I see now. Thanks! So right now I have it as…

    by Name • Updated: June 1, 2019

    1. How do I change “by Name” to “Written by: Name”?

    2. I also wanted to change the author link to a custom ‘about’ page rather than the default author page, so I found this in another thread:

    add_filter( 'author_link', 'my_author_link' );
    
    function my_author_link() {
    	return home_url( 'slug' );
    }

    And that works perfectly except for one thing: the title for the link remains “View all posts by Name”. Is there a way to change that to something else? If not, is there a way to just get rid of title on the author link altogether?

    Thanks again for the help!

    #968213
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    This function should handle both issues:

    add_filter( 'generate_post_author_output', function() {
        return sprintf( '<span class="byline">%1$s</span> ', // WPCS: XSS ok, sanitization ok.
            sprintf( '<span class="author vcard" %5$s>%1$s <a class="url fn n" href="%2$s" rel="author" itemprop="url"><span class="author-name" itemprop="name">%4$s</span></a></span>',
                __( 'Written by:', 'generatepress' ),
                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() ),
                generate_get_microdata( 'post-author' )
            )
        )
    } );

    Let me know 🙂

    #968819
    Jay

    Perfect! Thanks guys.

    #968945
    Tom
    Lead Developer
    Lead Developer

    You’re welcome 🙂

Viewing 10 posts - 1 through 10 (of 10 total)
  • You must be logged in to reply to this topic.