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.

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 &#8220;bodytext&#8221;

What should I do?

share|improve this question

1 Answer 1

up vote 2 down vote accepted

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.

share|improve this answer
    
That doesnt work. Is there a typo in the code? I added it in functions.php –  Dbugger May 15 '12 at 23:42
    
Ok, found. Its not post->title. Its post->post_title. Thanks! –  Dbugger May 16 '12 at 1:06
    
Thanks for catching that. Code updated. –  EAMann May 16 '12 at 5:00

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.