Title.php: return get_the_title() instead of the_title()

Hi! My first post… I want to thanks all the community and roots contributors! I love you all!

I was in need of giving the result of roots_title() to a $var.

I discovered that since the result of roots_title() was the_title(), I couldn’t store it since it is already printing the result.

I’ve noticed that in page-header.php we have ‘echo roots_title()’. As far I can imagine the echo is needed to print the result of the function. Why it is there if the function already prints its result?

Shouldn’t be the roots_title() function returning the result such as ‘return get_the_title()’ instead of the_title() [this is in the last else statement of title.php], and then if we need to print we use echo (for ex. in page-header.php), but if we need to store it in a $var we can use $var = roots_title(); ?

Isn’t this correct?

Thanks for pointing this out, it’s a good spot. Nothing should be echoed though, so you can’t just change the_title to get_the_title. The lines with printf _e and single_cat_title would all need to be changed too.

Would you like to issue a pull request on Github?

Hi Foxaii,

yes, sure also printf _e and single_cat_title should change, but I’m not skilled enough to know the best way to re-edit all them.

As for a pull request on Github I’d like to do it, but really don’t know how it works.
Still I have to understand and go deeper on the Github world!

Can you suggest how to change the printf _e and single_cat_title?

Thanks for your work!

Try sprintf, __ (double underscore) and single_cat_title('', false) instead.

There’s a guide to contributing if you want to give it a go. If not I’ll ask Ben, Scott and Chris what they think and do the PR myself.

1 Like

Thanks! It looks it works great in all different situations.

I’ll give a look at Github.
It could be an opportunity to understand it!

I’ll let you know.

@Foxaii just to let you know. I published a pull request on github to merge the changes.

Great! Thanks for showing me the way to contribute! :wink: