in the process of self learning from the official wordpress theme developement handbook
this page shows how to create headers and two different functions were used:
both return a string, which is the image URL.
is this just another confusing redundency ? or is there an actual difference between the two.
2
Answers
Semantic
dis·play
Make a prominent exhibition of (something) in a place where it can be easily seen.
re·trieve
get or bring (something) back; regain possession of.
How
While
header_image()
will echo out the header image URL,get_header_image()
will not.header_image()
is a wrapper forget_header_image()
. Mainly used on the front-end, the role is to escape and echo out get_header_image().A practical use case of
get_header_image()
would be inside a function.WordPress use that
get_ ...
distinction for most of it’s default functions, eg:get_the_title()
andthe_title()
.get_the_post_thumbnail()
andthe_post_thumbnail()
.get_the_content()
andthe_content()
.… etc.
I found the answer.
Someone posted it then deleted it quickly, but just for the sake of benefiting everyone who is looking for an answer:
header_image()
will echo the URL without the need of using the phpecho
. Whileget_header_image()
will also return the image URL but it doesn’t echo it. You have to use the php echo for it.NB: this isn’t mentioned in the official documentation, unless am blind I challenge anyone to show me where it says echo in the official page, or where this distinction is explained.