- This topic has 42 replies, 3 voices, and was last updated 5 years, 6 months ago by Tom.
-
AuthorPosts
-
September 13, 2018 at 6:45 pm #676806TomLead DeveloperLead Developer
Sorry for not getting back to you sooner!
Can you share the functions you’re currently using along with any CSS (relating to this topic)?
Just need to get an idea of what could be conflicting.
September 14, 2018 at 1:44 am #676950dassanathe function which i am using is with this css code.
September 14, 2018 at 8:08 am #677270TomLead DeveloperLead DeveloperThis function is causing the conflict:
if ( ! function_exists( 'generate_posted_on' ) ) : /** * Prints HTML with meta information for the current post-date/time and author. */ function generate_posted_on() { if ( 'post' !== get_post_type() ) return; $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() ) ); printf( __( '<span class="posted-on">%1$s</span> <span class="byline">%2$s</span>', 'generatepress' ), sprintf( '%1$s', $time_string ), sprintf( '<span class="author vcard" itemtype="http://schema.org/Person" itemscope="itemscope" itemprop="author">%1$s <span class="author-name" itemprop="name">%2$s</span></span>', __( 'by','generatepress'), esc_html( get_the_author() ) ) ); } endif;
If you remove it, does the function Leo provided work?
September 14, 2018 at 8:42 am #677292dassanathanks a lot tom. yes now it does work.
September 14, 2018 at 9:31 am #677336TomLead DeveloperLead DeveloperCan you turn off your caching plugin? I’m still seeing the old way you had set up.
So just to confirm, you want:
1. Only the modified date to show up in the source if it’s been modified, otherwise you want the published date to show up. Only 1 of the 2 should appear in the source at a time.
2. The date and author shouldn’t have links.
3. The comment count should be appended at the end of the line.
Correct?
September 14, 2018 at 9:41 am #677348dassanai have flushed the cache of this link from the server. can you refresh it and check again.
September 14, 2018 at 9:46 am #677352dassanaplease do refresh if you do not see the changes.
September 14, 2018 at 1:12 pm #677475TomLead DeveloperLead DeveloperYou have two different
posted-on
elements for some reason. Are you sure there aren’t any other functions hiding somewhere?If you want the structure to look like this: Date by author | comments
You can do this:
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 ); } add_filter( 'generate_post_author_output','tu_no_author_link' ); function tu_no_author_link() { printf( ' <span class="byline">%1$s</span>', sprintf( '<span class="author vcard" itemtype="http://schema.org/Person" itemscope="itemscope" itemprop="author">%1$s <span class="fn n author-name" itemprop="name">%4$s</span></span>', __( 'by','generatepress'), 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() ) ) ); if ( is_single() && ! post_password_required() && ( comments_open() || get_comments_number() ) ) { echo ' | <span class="comments-link">'; comments_popup_link( __( 'Leave a comment', 'generatepress' ), __( '1 Comment', 'generatepress' ), __( '% Comments', 'generatepress' ) ); echo '</span>'; } }
I don’t understand this part:
actually both should appear in the source code, but in the creative work and hatom fields, only the updated date should appear
Where would the published date appear in this case?
September 15, 2018 at 4:40 am #677754dassanahi tom
i added the code you have given and its looking good now.
September 15, 2018 at 9:32 am #677993TomLead DeveloperLead DeveloperTo show the updated date to humans, this should be all that’s necessary: https://docs.generatepress.com/article/show-the-updated-post-date/
We can try removing the structured data from the published date if a modified date exists by replacing this function:
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 ); }
With this:
add_filter( 'generate_post_date_output', function( $output, $time_string ) { $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 class="entry-date published">%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() ) ); return sprintf( '<span class="posted-on">%s</span>', // WPCS: XSS ok, sanitization ok. $time_string ); }, 10, 2 );
September 15, 2018 at 9:55 am #678009dassanathanks a ton tom. you have really gone out of the way to help me out. wish you all the best and great success. i do have some issues with styling, but that for later. i will try on my own and if i am not able to do, then i will post in forum. thanks again.
September 15, 2018 at 10:04 am #678014dassanaone issue here. the updated date is getting linked. how i do get rid of the link from the date.
September 15, 2018 at 8:24 pm #678229TomLead DeveloperLead DeveloperThere must be another function conflicting. The function we’re using above completely removes the link. Is there another post date filter in there?
September 16, 2018 at 3:12 am #678370dassanathanks tom. there was a function which you had given earlier. i have removed it.
September 16, 2018 at 3:13 am #678372dassanafor this url i have flushed the cache.
-
AuthorPosts
- You must be logged in to reply to this topic.