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.
Thread Starter
b-rad
(@b-rad)
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.