- This topic has 12 replies, 3 voices, and was last updated 2 years, 11 months ago by
Fernando.
-
AuthorPosts
-
April 4, 2023 at 7:57 am #2596559
Kev
Hey folks,
I’m building a site that’s basically gonna be a microblog, so I need to display the date and time of the post, as there will often be multiple posts per day. So instead of saying “04 April 2023” in the post meta, I’d like it to say “04 April 2023 at 14:25” for example.
Is there a way to do this easily?
Thanks,
Kev
April 4, 2023 at 7:57 am #2596560Kev
Forgot to enable notifications…
April 4, 2023 at 8:00 am #2596569Kev
Doh! I just figured out I can do it in WP Setting by using a custom time format. No need to respond to this.
April 4, 2023 at 9:32 am #2596693Ying
StaffCustomer SupportGlad you’ve figured it out 🙂
April 5, 2023 at 12:45 am #2597490Kev
Hey folks,
Sorry to re-open this. I changed the WP settings so that it displays date and time with
j F Y H:iwhich worked fine for posts, as it would display something like4 April 2023 23:12problem is when it comes to comments. Because they already include in the time in them, their meta appears like this –4 April 2023 23:19 at 23:19.Is there a way to fix this so that the date and time are displayed correctly everywhere?
Thanks,
Kev
April 5, 2023 at 1:00 am #2597527Fernando Customer Support
Hi Kev,
Can you try adding this snippet:
add_filter( 'get_comment_date', 'db_reformat_comment_date' ); function db_reformat_comment_date( $dateForm ) { $dateForm = date("j F Y H:i"); return $dateForm; }Adding PHP: https://docs.generatepress.com/article/adding-php/#code-snippets
April 5, 2023 at 1:09 am #2597537Kev
Adding that caused a critical error on my site. 🙁
April 5, 2023 at 1:24 am #2597556Fernando Customer Support
May we know how you added it?
April 5, 2023 at 1:36 am #2597568Kev
It’s a child theme, I added it via
functions.phpMy existing functions file is below. I appended it to the end.
<?php // Gutenberg custom stylesheet add_theme_support('editor-styles'); add_editor_style( 'style.css' ); add_editor_style( 'editor-style.css' ); // Remove block library stylesheet function remove_block_library_css(){ wp_dequeue_style( 'wp-block-library' ); } add_action( 'wp_enqueue_scripts', 'remove_block_library_css' ); // Remove "Archive:", "Category:" etc. add_filter( 'get_the_archive_title', function ($title) { if ( is_category() ) { $title = single_cat_title( '', false ); } elseif ( is_tag() ) { $title = single_tag_title( '', false ); } elseif ( is_author() ) { $title = '<span class="vcard">' . get_the_author() . '</span>' ; } elseif ( is_tax() ) { //for custom post types $title = sprintf( __( '%1$s' ), single_term_title( '', false ) ); } elseif (is_post_type_archive()) { $title = post_type_archive_title( '', false ); } return $title; }); // Shortcode for inserting the site's contact email add_shortcode( 'contact_email', 'contact_email' ); function contact_email( $atts ) { return '23g@qrk.one'; // Change this value when it's time to update your email everywhere! } // Shortcode for generating the post title add_shortcode( 'get_title', 'get_title' ); function get_title( $atts ) { return esc_attr( get_the_title( get_the_ID() ) ); } // Add reply link to RSS feed add_filter( "the_content_feed", "feed_comment_via_email" ); function feed_comment_via_email($content) { $content .= "<p><a href=\"mailto: " . do_shortcode( ' [contact_email] ' ) . "?subject=Reply to '" . do_shortcode( ' [get_title] ' ) . "'" . "\">Reply via email</a></p>"; return $content; } // Remove mobile menu and drop-down JS. add_action( 'wp_enqueue_scripts', 'tu_remove_menu_scripts', 50 ); function tu_remove_menu_scripts() { wp_dequeue_script( 'generate-menu' ); wp_dequeue_script( 'generate-dropdown' ); } // Disable comments RSS feed add_action( 'after_setup_theme', 'head_cleanup' ); function head_cleanup(){ // Add default posts and comments RSS feed links to head. add_theme_support( 'automatic-feed-links' ); // disable comments feed add_filter( 'feed_links_show_comments_feed', '__return_false' ); } // Auto-generate titles on posts based on date and time add_filter('default_title', function ($title) { global $post_type; if ('post' == $post_type) { return date('d F Y H:i'); } return $title; } );April 5, 2023 at 1:41 am #2597572Fernando Customer Support
I see. Will you be able to access it and remove it?
If you’re not able to access your site, access the file through FTP.
I tested the code here and it’s working from my end: https://generatepress.com/forums/topic/add-date-and-time-to-posts/#post-2597527
Can you check if there are any slanted quotation marks when your copying and pasting? Sometimes copying and pasting converts the straight quotation marks to slanted ones and that would cause issues.
April 5, 2023 at 1:58 am #2597583Kev
Weirdly it worked the second time. No idea why. Maybe something did go wrong when I pasted it, sorry about that.
Anyway, it’s in now, but the dates are still showing incorrectly. Here’s an example – https://log.kevquirk.com/04-april-2023-2312/
As you can see, the date at the top of the page is working correctly, but the date in the comment meta is wrong.
April 5, 2023 at 5:19 am #2597812Kev
I’ve managed to fix this by using a block element and the WP Date block and customising that. Thanks.
April 5, 2023 at 4:56 pm #2598760Fernando Customer Support
I see. Glad you resolved it! You’re welcome, Kev!
-
AuthorPosts
- You must be logged in to reply to this topic.