• Resolved fonnte

    (@fonnte)


    hello Tom

    thanks in advance for this super awesome theme. i am using generatepress for most of my website and i am happy for it

    i want to add to add posted on and updated on before the dates displayed as i show the post modified time
    https://s22.postimg.org/yyna144f5/Screenshot_10.png
    how is that possible?

    any help would be much appreciated

    • This topic was modified 7 years, 11 months ago by fonnte.
Viewing 3 replies - 1 through 3 (of 3 total)
  • Theme Author Tom

    (@edge22)

    Hi there,

    You could use the generate_post_date_output filter to alter the output: https://docs.generatepress.com/article/generate_post_date_output/

    add_filter( 'generate_post_date_output','tu_add_updated_date_output' );
    function tu_add_updated_date_output( $output ) {
        $time_string = 'Posted on: <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 .= ' Updated on: <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() )
        );
    
        return 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
    		)
    	);
    }

    Adding PHP: https://docs.generatepress.com/article/adding-php/

    Then of course, make sure the updated time displays with some CSS (which it looks like you’ve already done):

    .posted-on .updated {
        display: inline;
    }

    Adding CSS: https://docs.generatepress.com/article/adding-css/

    Thread Starter fonnte

    (@fonnte)

    wow, awesome Tom! it works perfectly.

    thanks a lot.

    Theme Author Tom

    (@edge22)

    You’re welcome ??

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘add text posted on and updated on’ is closed to new replies.