- This topic has 21 replies, 3 voices, and was last updated 5 years, 1 month ago by Tom.
-
AuthorPosts
-
March 5, 2019 at 5:35 pm #830055TomLead DeveloperLead Developer
In my code above, this element doesn’t exist:
<time class="updated"...
You’ll notice there’s no
updated
class.That means the second date is coming from somewhere else completely. Have you tried temporarily removing all other custom functions?
March 5, 2019 at 9:46 pm #830159epickenyanThat’s because it is coming from the theme’s post-meta.php http://prntscr.com/mtvvto (and like the others said, this code in itself is not being picked by Google and that’s why I am also seeking a working code.)
March 6, 2019 at 9:32 am #830757TomLead DeveloperLead DeveloperThe filter I provided replaces what’s in the
post-meta.php
file: https://github.com/tomusborne/generatepress/blob/2.2.2/inc/structure/post-meta.php#L129It completely overwrites the core markup with what we provide in the function.
It’s likely that one of your other functions is also adding the date, which is why we need to disable them to figure out which one.
March 6, 2019 at 12:52 pm #830947epickenyanI found it! The culprit is this function you gave me to move the location of the category link in the blog section https://generatepress.com/forums/topic/move-category-meta/page/2/#post-820187. I have disabled it for now but I would still like to use it.
Here is the source code
<div class="entry-meta"> <span class="posted-on"><time class="entry-date updated-date" datetime="2019-02-27T12:43:59+03:00" itemprop="dateModified">Feb 27, 2019</time></span> </div>
March 6, 2019 at 2:25 pm #831001TomLead DeveloperLead DeveloperAwesome. So your new single function would be:
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="entry-date updated-date" 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">%s</span> ', // WPCS: XSS ok, sanitization ok. $time_string ); if ( ! is_single() ) { $categories_list = get_the_category_list( ', ' ); if ( $categories_list ) { echo '<span class="cat-links">' . $categories_list . '</span>'; } } }, 10, 2 );
March 6, 2019 at 2:46 pm #831015epickenyanThanks! That worked like a charm.
March 6, 2019 at 3:06 pm #831036TomLead DeveloperLead DeveloperYou’re welcome 🙂
-
AuthorPosts
- You must be logged in to reply to this topic.