Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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
add comment

1 Answer

up vote 3 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
add comment

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.