- This topic has 13 replies, 3 voices, and was last updated 5 years, 9 months ago by Tom.
-
AuthorPosts
-
July 7, 2018 at 2:13 pm #618187Daren
Is there a way to show the last updated date in the footer meta and still display the post date below the title?
July 7, 2018 at 9:06 pm #618329TomLead DeveloperLead DeveloperWe should be able to code that up π
Do you want it to display in the post excerpt, the single post or both?
July 8, 2018 at 12:04 am #618377DarenLets go with both.
July 8, 2018 at 9:03 am #618656TomLead DeveloperLead DeveloperSo the best way to do this right now is to append it to the tags:
add_filter( 'generate_tag_list_output', 'tu_add_updated_date_to_footer_meta' ); function tu_add_updated_date_to_footer_meta( $output ) { $time_string = false; if ( get_the_time( 'U' ) !== get_the_modified_time( 'U' ) ) { $time_string = '<time class="updated" datetime="%1$s" itemprop="dateModified">%2$s</time>'; } if ( $time_string ) { $time_string = sprintf( $time_string, esc_attr( get_the_modified_date( 'c' ) ), esc_html( get_the_modified_date() ) ); $time_string = '<span class="updated-footer-date">' . $time_string . '</span>'; } return $output . $time_string; }
Let me know if this does it or not π
July 8, 2018 at 10:56 am #618707DarenIt displays the date below the tag meta as July 7, 2018. How do I add the Last Updated text?
I you need to look I updated the first post with the URL.July 8, 2018 at 12:42 pm #618751DarenDid more testing and the date only shows if a post has a tag defined.
July 8, 2018 at 5:47 pm #618881DarenOk, I think I got it with the help of some old code. Could you please review the code, it does work.
<?php if ( ! function_exists( 'generate_entry_meta' ) ) : /** * Prints HTML with meta information for the categories, tags. * * @since 1.2.5 */ function generate_entry_meta() { $categories = apply_filters( 'generate_show_categories', true ); $tags = apply_filters( 'generate_show_tags', true ); $comments = apply_filters( 'generate_show_comments', true ); $date = apply_filters( 'generate_post_date', true ); $author = apply_filters( 'generate_post_author', true ); if ( 'post' == get_post_type() ) { if ( get_the_time( 'U' ) !== get_the_modified_time( 'U' ) ) { $time_string = '<time class="updated-on" datetime="%1$s" itemprop="dateModified">%2$s</time>'; $time_string = sprintf( $time_string, esc_attr( get_the_modified_date( 'c' ) ), esc_html( get_the_modified_date() ) ); // If our date is enabled, show it if ( $date ) : printf( '<span class="entry-date updated">%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 ) ); endif; // If our author is enabled, show it if ( $author ) : $origional_author = get_the_author(); $modified_author = get_the_modified_author(); // If modified by a new author show it if ( $origional_author !== $modified_author ) { printf( ' <span class="modified-byline">%1$s</span>', sprintf( '<span class="modified-author vcard" itemtype="http://schema.org/Person" itemscope="itemscope" itemprop="author">%1$s <a class="url fn n" href="%2$s" title="%3$s" rel="author" itemprop="url"><span class="author-name" itemprop="name">%4$s</span></a></span>', __( 'by','generate'), esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ), esc_attr( sprintf( __( 'View all posts by %s', 'generate' ), get_the_modified_author() ) ), esc_html( get_the_modified_author() ) ) ); } endif; } $categories_list = get_the_category_list( _x( ', ', 'Used between list items, there is a space after the comma.', 'generate' ) ); if ( $categories_list && $categories ) { printf( '<span class="cat-links"><span class="screen-reader-text">%1$s </span>%2$s</span>', _x( 'Categories', 'Used before category names.', 'generate' ), $categories_list ); } $tags_list = get_the_tag_list( '', _x( ', ', 'Used between list items, there is a space after the comma.', 'generate' ) ); if ( $tags_list && $tags ) { printf( '<span class="tags-links"><span class="screen-reader-text">%1$s </span>%2$s</span>', _x( 'Tags', 'Used before tag names.', 'generate' ), $tags_list ); } } if ( ! is_single() && ! post_password_required() && ( comments_open() || get_comments_number() ) && $comments ) { echo '<span class="comments-link">'; comments_popup_link( __( 'Leave a comment', 'generate' ), __( '1 Comment', 'generate' ), __( '% Comments', 'generate' ) ); echo '</span>'; } } endif;
July 8, 2018 at 11:45 pm #618958LeoStaffCustomer SupportHey! Tomβs wife is in labor, he will get to this topic as soon as he can π
July 9, 2018 at 8:43 am #619397TomLead DeveloperLead DeveloperThat works, but using a filter is preferred. However, it is required that tags or categories are active in order to add the filter (for now).
The solution you found will work until we add a hook into the meta area π
July 9, 2018 at 9:04 am #619423DarenThank you.
July 9, 2018 at 9:05 am #619425TomLead DeveloperLead DeveloperNo problem π
July 9, 2018 at 9:18 am #619443DarenHey back on the filter idea, could we use the generate_category_list_output and display before the cats are displayed?
July 9, 2018 at 6:04 pm #619760DarenTook your advice and went the filter route.
add_filter( 'generate_category_list_output', 'dw_add_updated_date_to_footer_meta' ); function dw_add_updated_date_to_footer_meta( $output ) { $time_string = false; if ( ! is_front_page() && ! is_home() ) { if ( get_the_time( 'U' ) !== get_the_modified_time( 'U' ) ) { $time_string = '<time class="updated" datetime="%1$s" itemprop="dateModified">%2$s %3$s</time>'; } if ( $time_string ) { $time_string = sprintf( $time_string, esc_attr( get_the_modified_date( 'c' ) ), __( 'Last Updated:','generatepress'), esc_html( get_the_modified_date() ) ); $time_string = '<span class="updated-on">' . $time_string . '</span>'; } } return $time_string . $output; }
Works fine.
July 9, 2018 at 8:50 pm #619826TomLead DeveloperLead DeveloperAwesome! Glad you got it working π
-
AuthorPosts
- You must be logged in to reply to this topic.