• Hello,

    I would like to display the date of publication in my post (with the Post Date block), but if the post has been modified, the modification date should be displayed.

    But with the post date block this is not possible.

    If I set the block to Last modified Date, then no date is displayed if the post has not been modified. If I do not select Last modified Date, then only the publication date is displayed, but not the modification date.

    It is also not possible to show the Dates in this Format:

    Date: 1.6.2024 / Updated: 15.6.2024

    Because if the post was not updated, then the word “Updated:” is shown, but with no date.

    So the Post Date block makes no sense to me, as it is not usable for these purposes.

    Is there another way to indicate in a post when it was modified?

    • This topic was modified 4 months, 3 weeks ago by mak68.
Viewing 5 replies - 1 through 5 (of 5 total)
  • The decisive factor in your question is that you want to display a text before the “Modified Date” – and only if such a date exists at all. Other blocks already have a prefix and suffix for this, e.g. the category block. Unfortunately, there is still an open issue with the Gutenberg team regarding the Post Date block: https://github.com/WordPress/gutenberg/issues/47738

    But I also feel like I’ve seen this somewhere before. It could be that there are plugins that make this possible.

    Thread Starter mak68

    (@mak68)

    That’s right! That’s exactly the problem. If there was a prefix that was only displayed when the date was displayed, I could use the updated date. Unfortunately, this is not possible. I hope that this will be changed soon. However, when I see how old the Github entry is, I don’t think anything will be done about it. I don’t understand that at all, as everyone should actually have a problem with it.

    I have already tested some plugins that promise an update date. But none of them have worked so far. They probably don’t know about this block yet.

    This is really annoying, as it makes my block theme almost unusable for me, as I need this function.

    Hello,

    I wanted to share a solution for displaying both the publication date and the last modified date in my blog posts. Initially, I struggled with the Post Date block because it wouldn’t show both dates in the format I wanted. Here’s what I did to make it work:Step-by-Step Guide

    1. Add Custom Code to Your Theme: I added the following PHP code to my theme’s functions.php file. This code checks if the post has been modified and displays the dates accordingly.

    function display_post_dates() {
    $published_date = get_the_date(‘j.n.Y’);
    $modified_date = get_the_modified_date(‘j.n.Y’);

    if ($published_date === $modified_date) {
        echo 'Date: ' . $published_date;
    } else {
        echo 'Date: ' . $published_date . ' / Updated: ' . $modified_date;
    }

    }

    Use a Shortcode in Your Posts: I created a shortcode to easily insert the dates in my posts. Add this to your functions.php as well:

    function post_dates_shortcode() {
    ob_start();
    display_post_dates();
    return ob_get_clean();
    }
    add_shortcode(‘post_dates’, ‘post_dates_shortcode’);

    1. Insert the Shortcode in Your Posts: Now, I can simply insert [post_dates] in any post where I want the dates to appear.

    Final Result

    By using this method, the dates are displayed as follows:

    • If the post hasn’t been modified: Date: 1.6.2024
    • If the post has been modified: Date: 1.6.2024 / Updated: 15.6.2024

    This way, I don’t end up with the word “Updated:” without a date if the post hasn’t been modified. It’s a neat and dynamic solution that ensures my posts always display the correct dates.

    Hope this helps anyone facing the same issue!

    Thread Starter mak68

    (@mak68)

    Hello,

    thank you for posting your solution here. I am glad that this works for you.

    However, for me it is not a solution to manually insert a shortcode into each of my articles.

    If you use a template for all posts, you only need to store the shortcode in the template and not in each post.

    You can also use this shortcode in the query loop block, I think. You don’t have to enter it every time there either.

Viewing 5 replies - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.