- This topic has 19 replies, 3 voices, and was last updated 3 years, 8 months ago by David.
-
AuthorPosts
-
August 5, 2020 at 8:00 am #1388374Rohan Verma
Hello.
I want to achieve both the published and updated text for the article date on a single post.
Currently, it’s only showing the updated text for updated article.
1. Similarly, I want published text for the single time published article.
2. And I have followed a PHP code for getting date icon on other topic. But the icon is showing after the date. How can I place it before published/updated text?August 5, 2020 at 12:37 pm #1388666TomLead DeveloperLead DeveloperHi there,
This article should help: https://docs.generatepress.com/article/show-the-updated-post-date/
Your CSS would look like this:
.posted-on .updated { display: inline-block; } .posted-on .updated:before { content: "Last Updated "; } .posted-on .entry-date:before { content: "Published "; }
Which code have you added to add the icon? Where’s the icon coming from exactly? A custom SVG?
August 5, 2020 at 12:58 pm #1388684Rohan VermaI’m talking about the Add Icon to Date code.
https://docs.generatepress.com/article/generate_post_date_output/#only-show-updated-date
August 5, 2020 at 1:12 pm #1388695Rohan VermaAccording to your given code, the date tag shows double: https://prnt.sc/tuoib7
I don’t want like this. There will be only one tag. Not both published and updated.
Either it will show Published for the fresh articles or it will show Updated for the updated articles.
Hope you understand.
August 6, 2020 at 12:51 am #1389078DavidStaffCustomer SupportHi there,
in this article:
https://docs.generatepress.com/article/generate_post_date_output/#only-show-updated-dateThe code has two
$time_string
variables – only one will be displayed. The first is for the published date, change it to this:$time_string = '<time class="entry-date published" datetime="%1$s" itemprop="datePublished">Published %2$s</time>';
The second line change to this:
$time_string = '<time class="entry-date updated-date" datetime="%3$s" itemprop="dateModified">Last Updated %4$s</time>';
August 6, 2020 at 2:37 am #1389173Rohan VermaHi David, But your given two strings are similar to that link.
So, what to change for published and updated?
August 6, 2020 at 2:50 am #1389192DavidStaffCustomer SupportThe code changes i provided above include the Published and Last Updated labels.
So your updated code would look like this:add_filter( 'generate_post_date_output', function( $output, $time_string ) { $time_string = '<time class="entry-date published" datetime="%1$s" itemprop="datePublished">Published %2$s</time>'; $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">Last Updated %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">%s</span> ', $time_string ); }, 10, 2 );
August 6, 2020 at 2:55 am #1389200Rohan VermaNow, it looks like these two.
I don’t want to show both together. Only one needs to show which one is the latest.
August 6, 2020 at 3:00 am #1389209DavidStaffCustomer SupportWhat other post meta related functions have you added to your site ?
August 6, 2020 at 3:09 am #1389219Rohan VermaRemove link from date.
Show author avatar beside the name.
Author box hook element.There are a bunch of css codes but I don’t know any of them conflicting or not. Should I share with you the css codes…
August 6, 2020 at 3:24 am #1389234DavidStaffCustomer SupportIts not the CSS.
It will be either the remove link and/or show avatar.
Can you share them hereAugust 6, 2020 at 3:27 am #1389240Rohan VermaShow avatar:
add_filter( 'generate_post_author_output', function() { return sprintf( ' <span class="byline">%1$s</span>', sprintf( '<span class="author vcard" itemtype="http://schema.org/Person" itemscope="itemscope" itemprop="author">%4$s<a href="%1$s" title="%2$s" rel="author"><span class="author-name" itemprop="name">%3$s</span></a></span>', esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ), esc_attr( sprintf( __( 'View all posts by %s', 'generatepress' ), get_the_author() ) ), esc_html( get_the_author() ), get_avatar( get_the_author_meta( 'ID' ) ) ) ); } ); add_filter( 'generate_header_entry_meta_items', function() { return array( 'author', 'comments-link', 'date', ); } );
August 6, 2020 at 3:27 am #1389241Rohan VermaRemove link:
add_filter( ‘generate_post_date_output’,’tu_remove_date_link’, 10, 2 );
function tu_remove_date_link( $output, $time_string ) {
printf( ‘<span class=”posted-on”>%s</span>’,
$time_string
);
}August 6, 2020 at 5:48 am #1389348DavidStaffCustomer SupportRemove the ‘remove link’ function
August 6, 2020 at 5:55 am #1389356Rohan VermaThanks. It’s working.
1. But how to add : symbol after published or updated text?
2. How can I make the bold font of both author and published/updated text? -
AuthorPosts
- You must be logged in to reply to this topic.