WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to add a custom "Tweet this" button to my WordPress posts. I'm sticking to the official Twitter guidelines.

Here is what I'm actually trying to pull of; I don't want the button, I want a custom look - for me it's only text. This is the code I use:

<a href="https://twitter.com/share?url=<?php echo urlencode(get_permalink($post->ID)); ?> &text=<?php the_title(); ?> &via=username&count=horizontal" class="custom-tweet-button">Tweet</a>


This is the post title via @username

So the problem is that the permalink (<?php the_permalink(); ?>)doesn't get displayed.

I tried:

  • https://twitter.com/share?url=<?php echo urlencode(get_permalink($post->ID)); ?>
  • https://twitter.com/share?url=<?php the_permalink(); ?>

PS: I also tried the standard twitter button, not the custom one, but the permalink doesn't get displayed either.

Does anyone one if something is wrong with my code or if this is a problem since I'm using a local WordPress for development?

share|improve this question
up vote 0 down vote accepted

After sleeping over the problem I decided to the code and tried this:

<a href="https://twitter.com/share?url=&text=<?php the_title(); ?>: <?php echo urlencode(get_permalink($post->ID)); ?> &via=username&count=horizontal" class="custom-tweet-button">Tweet</a>

All I can say is: it works as it should be. Next thing on my agenda is to incorporate a custom url shortener.

PS: It's worth a mention that if you use certain themes, they might use a special %permalink% and %post-title% structure. Be sure to replace the default <?php the_title(); ?> and <?php the_permalink(); ?> with it.

share|improve this answer
If you need Facebook and Google+ as well take a look here: gist.github.com/4610722 – pattulus Jan 23 '13 at 17:40

Your Answer


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.