[Resolved] Published on / Update on PHP

Home Forums Support Published on / Update on PHP

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #1681970
    Sam

    Hey

    I saw in an old post a snipper of php that changed the element header to show Published on, updated On.

    Works a treat, the only side effect is now all my posts have the created date as the first line of the body – how can I remove/hide that

    function db_modified_time_stamp( $output, $time_string ) {
            $time_string = '<time class="entry-date published" datetime="%1$s" itemprop="datePublished">Published on %2$s</time> ';
    
        if ( get_the_time( 'U' ) !== get_the_modified_time( 'U' ) ) {
           	$time_string = '<time class="updated" datetime="%3$s" itemprop="dateModified">Updated on %4$s</time> ' . $time_string;
        }
    	
    	// get modified time and published time. Compare the two, If modified date exists then ouput both time strings with modified date
    	$updated_time = get_the_modified_time( 'U' );
        $published_time = get_the_time( 'U' ) + 86400;
        
        if ( $updated_time > $published_time ) {
            $time_string = '<time class="entry-date updated-date" datetime="%3$s" itemprop="dateModified" style="display:inline;">Updated on %4$s</time>';
        }
    
            $time_string = sprintf( $time_string,
                esc_attr( get_the_date( 'c' ) ),
                esc_html( get_the_date('F j, Y') ),
                esc_attr( get_the_modified_date( 'c' ) ),
                esc_html( get_the_modified_date('F j, Y') )
            );
    
            return sprintf( '<span class="posted-on">%1$s</span>', // WPCS: XSS ok, sanitization ok.
                sprintf( '<a href="%1$s" title="%2$s" rel="bookmark">%3$s</a>',
                    esc_url( get_permalink() ),
                    esc_attr( get_the_time() ),
                    $time_string
                )
            );
    }
    
    add_shortcode( 'hero_date','db_modified_time_stamp' );

    Screenshot issue

    https://share.getcloudapp.com/DOu2EZNA

    #1682148
    David
    Staff
    Customer Support

    Hi there,

    you can remove that in Customizer > Layout > Blog –> Single

    https://docs.generatepress.com/article/blog-content-layout/#single

    #1682177
    Sam

    Super star! Cheers David

    #1682376
    David
    Staff
    Customer Support
Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.