the_title()
echoes the title, meaning that it prints the title to the page as soon as the function executes. It’s generally the convention in WordPress that functions starting with the_
echo their output.
get_the_title()
returns the value, meaning that you can use it to pass the title into a variable, or into another function, without printing it to the page.
So, in your template, when you write:
<?php get_post_format(); ?>
You’re returning the post format to… nothing. It’s just getting post format and throwing it out into the ether. WordPress doesn’t have a the_post_format()
function, because it’s not a value that you normally need to output, so to print it to the page you need to echo the value it returns, like so:
<?php echo get_post_format(); ?>
That will show you the post format.
The problem with <?php get_post_format(the_ID()); ?>
is that the_ID()
echoes the ID, while get_post_format()
returns the post format. So essentially it’s just printing the ID. If you need to pass an ID to get_post_format()
, use the get_the_ID()
function:
<?php echo get_post_format( get_the_ID() ); ?>
The get_
vs the_
rule is a sort-of useful shorthand for WordPress, but not a perfect rule (some get_
functions have options for echoing, for example). The only way to know for sure whether a function echos or returns is to experiment or refer to the documentation. WordPress’ function documentation is here: https://developer.www.ads-software.com/reference/functions/
Thanks for the help.
]]>