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="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:

Read More

Give format to “bodytext”

and when I tweet it, the quotes appear as

Give format to “bodytext”

What should I do?

Related posts

Leave a Reply

1 comment

  1. 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.