Support » Fixing WordPress » What's the difference between the_modified_date and get_the_modified_date?

  • Resolved b-rad

    (@b-rad)


    The description for the_modified_date says:

    This tag displays the date (and time) a post was last modified.

    But at the end it also says:

    Use get_the_modified_date() to retrieve the value.

    Going to get_the_modified_date says:

    Retrieve the date on which the post was last modified.

    So how are they different? And similarly, how are the_modified_time and get_the_modified_time different?

Viewing 5 replies - 1 through 5 (of 5 total)
  • Moderator stephencottontail

    (@stephencottontail)

    the_modified_date() simply writes the output directly to the page, whereas get_the_modified_date() returns the value so you can store it into a variable for further processing.

    If you do:

    <?php printf( '<span class="modified">%s</span>', the_modified_date() ); ?>

    the output will be

    September 4, 2015<span class="modified"></span>

    Oops, probably not what you wanted.

    If you use this code, though:

    <?php printf( '<span class="modified">%s</span>', get_the_modified_date() ); ?>

    the output will be

    <span class="modified>September 4, 2015</span>

    That’s better.

    In general, all of the functions with that naming pattern work the same way.

    Also, be careful if you are echoing something which along the way includes the_function() as it will throw errors. If that happens, use get_the_function() instead.

    Thanks for the clarification.

    Just a further question to understand your example.

    If you do:
    <?php printf( ‘<span class=”modified”>%s</span>’, the_modified_date() ); ?>
    the output will be
    September 4, 2015<span class=”modified”></span>
    Oops, probably not what you wanted.

    If you use this code, though:
    <?php printf( ‘<span class=”modified”>%s</span>’, get_the_modified_date() ); ?>
    the output will be
    <span class=”modified>September 4, 2015</span>

    Couldn’t we achieve the
    <span class=”modified>September 4, 2015</span>
    with

    <span class="modified">
    <?php printf( the_modified_date() ); ?></span>

    ?
    If we can, this has also the added benefit of avoiding the %s stuff.

    If we can, this has also the added benefit of avoiding the %s stuff.

    That’s for internationalization.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘What's the difference between the_modified_date and get_the_modified_date?’ is closed to new replies.