3

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?

7

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 '11 at 5:56
  • what do I have to do when I want to use this outside of the loop? e.g. in my sidebar? – mathiregister Apr 7 '11 at 6:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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