We're merging with GenerateBlocks! Learn more here.

[Resolved] Created date on first publish, updated date on update after

Please login to receive premium support.

Support for the free plugin can be found here.

Home Forums Pro Support Created date on first publish, updated date on update after

  • This topic has 11 replies, 2 voices, and was last updated 4 years ago by Tom.
Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #9834
    Daniel
    Participant

    Hi,

    I want to show the created or updated date on my posts. I want the created date the first time a post is published and after only showing updated date.

    In the Meta section i see only Include date checkbox which from my understanding is the creation date.

    The first time I publish I want to be able to show “Created on june 1, 2019” and one week later, if I’m updating the post, I want to show “Updated on june 7, 2019”.

    Is there any way to do that? If not, will you consider to add that feature on your roadmap?

    Thank you,

    #9857
    Tom
    Keymaster
    #9860
    Daniel
    Participant

    Hi Tom,

    Concerning the date, it seem to work, I do see the last updated date for the posts.

    What should I do in order to prefix the date with the text “Published on” vs “Updated on” depending on if it is the first time publish vs an update?

    #9867
    Tom
    Keymaster

    Give this a shot:

    .wp-show-posts-entry-date:before {
        content: "Created on ";
    }
    
    .wp-show-posts-updated:before {
        content: "Updated on ";
    }
    #9871
    Daniel
    Participant

    I created a new post and I see “Updated on ” + date, not “Created on ” + date. (In French, “Publié le ” + “Mis à jour le “)

    Here is all I have done trying to make it work.

    I created the following code snippet:

    
    add_filter( 'wpsp_date_output', 'tu_wpsp_updated_date_first' );
    function tu_wpsp_updated_date_first() {
    	$time_string = '';
    	
    	if ( get_the_time( 'U' ) !== get_the_modified_time( 'U' ) ) {
    		$time_string .= '<time class="wp-show-posts-updated" datetime="%3$s" itemprop="dateModified">%4$s</time>';
    	}
    	
    	$time_string .= '<time class="wp-show-posts-entry-date published" datetime="%1$s" itemprop="datePublished">%2$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
    	$output = sprintf(
    		'<span class="wp-show-posts-posted-on wp-show-posts-meta">
    			<a href="%1$s" title="%2$s" rel="bookmark">%3$s</a>
    		</span>',
    		esc_url( get_permalink() ),
    		esc_attr( get_the_time() ),
    		$time_string
    	);
    
    	return $output;
    	
    }
    

    I added the following custom CSS:

    
    /* Created after updated date */
    .wp-show-posts-updated {
        display: inline-block;
    }
    
    .wp-show-posts-updated + .wp-show-posts-entry-date {
        display: none;
    }
    
    /* Created after updated date label */
    .wp-show-posts-entry-date:before {
        content: "Publié le ";
    }
    
    .wp-show-posts-updated:before {
        content: "Mis à jour le ";
    }
    

    I commented any previous CSS customization attempt.

    #9900
    Tom
    Keymaster

    Hmm, WordPress itself decides whether a post is new or updated. Was this a brand new post that hasn’t been published/saved as a draft?

    #9901
    Daniel
    Participant

    It was a brand new published post. wirecutter.com use WordPress and they seem able to sort between “published on” vs “updated on”.

    I guess I will have to live with “updated on” all of the time instead of “published on” + “updated on” if it require too much work in order to achieve.

    #9919
    Tom
    Keymaster

    Can you link me to a page which has a post that’s never been updated?

    #9922
    Daniel
    Participant

    https://www.optionparent.com/, the post named “Meilleurs tire-laits électriques” below the section label “Alimentation”
    I’ve just published this post for the first time 5 minutes ago, i will not update it in the short term.

    #9945
    Tom
    Keymaster

    Strange – I’ll do some tests on this and will update you 🙂

    #11117
    Daniel
    Participant

    The problem has not reappeared since the opening of the ticket so I consider it to be a non-recurring intermittent problem that is unlikely to recur easily so we can close this post.

    #11184
    Tom
    Keymaster

    Thanks for letting me know 🙂

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