2

I am looking to use the 'the_modified_date' function to display the date and time of a specific post has been modified. This information will appear in the header of our website on every single page.

How would I go about completing this?

I can use to get the title, and was hoping there would be a way just as easy to display that posts date and time.

Thank you for your help.

1

Place this code snippet put in function.php, this should give you what you need.

function my_theme_wp_title( $title, $sep ) {
    global $post;

    /* my other title cases */

    //get post's modified date
    $m_date = get_the_modified_date();

    //concatenate the current title with the date string, using the separator to be more clear
    $title .= $sep . " " . $m_date;

    return $title;
}
add_filter( 'wp_title', 'my_theme_wp_title', 10, 2 );

Basically we add our custom function hooked to the wp_title filter, thus altering wp_title function, giving us the flexibility to add custom logic in the title display.

Cheers!

  • Answers should be more that just a bunch of code. Please file an edit and add an explanation to how your code works and how it should be used and where it should be used. Thank you – Pieter Goosen Nov 24 '14 at 10:02
-1

Kindly refer below :

    <?php if (get_the_modified_time() != get_the_time()) : ?>

    <p>Posted: <?php the_time('F j, Y'); ?> at <?php the_time('g:i a'); ?>, 
    Last Updated: <?php the_modified_time('F j, Y'); ?> at <?php the_modified_time('g:i a'); ?></p>

<?php else: ?>

    <p>Posted: <?php the_time('F j, Y'); ?> at <?php the_time('g:i a'); ?></p>

    <?php endif; ?>
  • Just a note on the update, an explanation where the code should go and how it works will be nice. Remember, this answer should be a reference for others aswell, not just the OP – Pieter Goosen Nov 24 '14 at 6:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.