WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
up vote 6 down vote accepted

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()) ?>
share|improve this answer
    
+1 because I forget the get almost everytime I use these functions :) – BandonRandon 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

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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