Celebrating 7 Years! Get up to $30 off GeneratePress Premium!

[Support request] Customize Post Meta

Home Forums Support [Support request] Customize Post Meta

Home Forums Support Customize Post Meta

Viewing 15 posts - 1 through 15 (of 16 total)
  • Author
    Posts
  • #592942
    Carson

    Hi,

    I read a few threads about this on here already, but unfortunately I lack the coding skills to achieve my desired results, using one of the answers you guys already gave.

    So I want to change the Post meta to display something like this:

    Written by [Author]|Last updated on August 15, 2017

    Appreciate any help!

    GeneratePress 2.1.2
    GP Premium 1.6.2
    #592975
    Leo
    Staff
    Customer Support
    #593086
    Carson

    That already helps a lot, thanks!

    Two more questions:
    How would I move the author in front of the date?
    How do I make so the date isn’t a link?

    #593641
    Tom
    Lead Developer
    Lead Developer

    That should be possible with a filter.

    First, disable the author inside of the Customizer.

    Then add this function:

    add_filter( 'generate_post_date_output', 'tu_author_in_front_of_date', 10, 2 );
    function tu_author_in_front_of_date( $date, $time_string ) {
    	$author = sprintf( ' <span class="byline">%1$s</span>', // WPCS: XSS ok, sanitization ok.
    		sprintf( '<span class="author vcard" itemtype="https://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' ) ) ),
    			/* translators: 1: Author name */
    			esc_attr( sprintf( __( 'View all posts by %s', 'generatepress' ), get_the_author() ) ),
    			esc_html( get_the_author() )
    		)
    	);
    
    	$date = sprintf( '<span class="posted-on">%s</span>', $time_string );
    
    	return $author . $date;
    }
    #601931
    Carson

    This doesn’t work unfortunately.

    With and without the snippet it doesn’t result into what I need.

    “Written by Author | Last updated on April 21, 2018”

    Also for some reason the snippet doesn’t work anymore to show the “Last update date”.

    #602114
    Tom
    Lead Developer
    Lead Developer

    That’s strange – I just tested it and it’s working for me.

    How did you add the function?

    #602168
    Carson

    I used the Code Snippets plugin to add the snippet.

    #602347
    Tom
    Lead Developer
    Lead Developer

    And it’s activated? Can you link me to your site with the snippet added?

    #602546
    Carson

    EDIT:

    I think the problem was that I placed it at the bottom of my CSS file, now it’s working fine. Thanks a lot!

    #602776
    Tom
    Lead Developer
    Lead Developer

    Awesome, glad I could help ๐Ÿ™‚

    #688019
    Evgeniya

    Hi,
    I have tried to add filter in post #593641, but it did something strange. It just repeated post updated date and author meta 2 times.
    Maybe it has something to do whith my other filter:
    add_filter( ‘generate_post_date_output’, ‘tu_show_modified_date’ );
    function tu_show_modified_date() {
    $time_string = ‘<time class=”entry-date published” datetime=”%1$s” itemprop=”datePublished”>%2$s</time>’;

    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() )
    );

    printf(
    ‘<span class=”posted-on”>%1$s</span>’, // WPCS: XSS ok, sanitization ok.
    sprintf( ‘%3$s‘,
    esc_url( get_permalink() ),
    esc_attr( get_the_time() ),
    $time_string
    )
    );
    }

    I just wanted post meta in this order: Author: + Gravatar + author’s name + Last updated: + date
    Can you help me with this?

    #688232
    Tom
    Lead Developer
    Lead Developer

    What’s that function doing exactly?

    I assume you have other functions to add the gravatar?

    Let me know ๐Ÿ™‚

    #688272
    Evgeniya

    That function shows modified date with words “Last updated” but only if post was updated. If post was not updated it shows published date without words “Last updated”.
    I deleted previous function to add Gravatar because it looked like it repeats half of the code to show author and the date in post #593641.

    #688742
    Tom
    Lead Developer
    Lead Developer
    #689174
    Evgeniya

    Hi Tom,
    I have added CSS for post updated date like you suggested. So far it works fine. But i have few more questions about function in post #593641:
    – How can i add gravatar foto in there?
    – How do i make an interval between author’s meta and date? Because now date appears right after author’s meta without even slightest gap.
    – How can i make all this post meta appear in this form only in single posts? And in the main page and archive page only show date? Because now in main page and archive page shows author’s meta although i checked off “Display post author” in Customizer.

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