Including a post title in a twitter link

Im trying to make a Twitter button on each article of my blog. This is the code I use on single.php

<a href="<?php echo urlencode(get_the_title()); ?>">
Tweet this!

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?

Solutions Collecting From Web of "Including a post title in a twitter link"

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 (“) and urlencode() will break it.

So instead, write your own title function and use that:

function my_get_the_title() {
    global $post;

    return $post->post_title;

This should bypass any unwanted filters and let you work with regular quotes.