[Resolved] Add updated date and time alongside published date and time to posts

Home Forums Support Add updated date and time alongside published date and time to posts

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #370751
    itesla

    Good day, as per title say looking for a code to add in child theme functions php file already searched most topics but can’t make it to work on my site to display like this under title in one line.
    Published on (Date) at (Time) | Updated on (Date) at (Time) by (Author)
    I know many people asking about this but it does not work with my site those codes and i try already many hours but the codes are complicated.

    GeneratePress 1.4
    GP Premium 1.4.3
    #370946
    Tom
    Lead Developer
    Lead Developer
    #371114
    itesla

    Yes the dates only are shown without time and without words just linked together looks ugly even if i change to block still not as desired.
    I want to customize them with words and time for each published and updated like this.
    Published on (Date) at (Time) | Updated on (Date) at (Time) by (Author)
    Tried different combinations but could not make it work as i need that is why i decided to ask how to edit this code.

    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 );
    		
    	$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() )
    	);
    	
    	// If our date is enabled, show it
    	if ( $date ) {
    		echo apply_filters( 'generate_post_date_output', sprintf( '<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
    			)
    		), $time_string );
    	}

    I know this is out of support so i would like to donate as you helped me with other codes before.
    Thank you for your time.

    #371688
    Tom
    Lead Developer
    Lead Developer
    #371841
    itesla

    It works, you are the best.
    I have send you a small donation.
    Thank you!

    #372062
    Tom
    Lead Developer
    Lead Developer

    Thank you! I really appreciate it! 🙂

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