1

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?

3

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.

  • That doesnt work. Is there a typo in the code? I added it in functions.php – Enrique Moreno Tent May 15 '12 at 23:42
  • Ok, found. Its not post->title. Its post->post_title. Thanks! – Enrique Moreno Tent May 16 '12 at 1:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.