Im trying to make a Twitter button on each article of my blog. This is the code I use on single.php
<a href="http://twitter.com/home?status=<?php echo urlencode(get_the_title()); ?>">
Tweet this!
</a>
The problem is that I have a blog post with this title:
Give format to âbodytextâ
and when I tweet it, the quotes appear as
Give format to “bodytext”
What should I do?
The problem is that
get_the_title()
will pass the title through a filter that texturizes the quotes. So a regular ” becomes a curly quote (“) andurlencode()
will break it.So instead, write your own title function and use that:
This should bypass any unwanted filters and let you work with regular quotes.