hey guys, <?php urlencode(the_title()); ?>doesn't take effect.

this is my entrie line of code:

<li><a href="mailto:?subject=<?php urlencode(the_title()); ?>&amp;body=<?php the_permalink(); ?>">e-mail</a></li>

I don't want to have spaces in the_title(). Why does urlencode not work for me?

1 Answer 1


The the_title() echo the title. You must use get_the_title() instead. get_the_title() returns the title as string. Use

<? echo urlencode(get_the_title()) ?>
  • +1 because I forget the get almost everytime I use these functions :)
    – Brooke.
    Apr 7, 2011 at 5:56
  • what do I have to do when I want to use this outside of the loop? e.g. in my sidebar? Apr 7, 2011 at 6:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.