Noob question. Is there another way of getting a posts title without using the_title();
I’m asking because I am using a function the take a string parameter, then after some code, returns this string. When I pass in the_title(); as this parameter, for some reason it isn’t coming in as a string, therefore, the method fails.
When I pass in “some random string” instead of the_title(); the function works properly.
Make sense?
This is because
the_title()
echos the post title (see the linked documentation). Useget_the_title()
instead which returns the title as a string.Edit
You have two options:
get_the_title()
to return, rather than echo, the post titlethe_title
to echo a custom string as the post titleUsing
get_the_title()
Using
the_title
filter