Official Twitter Tweet Button: Adding it to WordPress

Look!  The official Twitter tweet button is here!  Get the official Twitter Tweet Code.  Ah, but it’s not quite so straight forward for a WordPress site.

Twitter Tweet Button code generator makes life easy... but modification is required for WordPress sites.

Twitter Tweet Button code generator makes life easy... but modification is required for WordPress sites.

Adding the official button to WordPress (like on this site) takes a little more.  The code you get from using the Twitter generator I linked to above looks like this:

That works perfectly well for static pages.  But the index page of a WordPress blog contains more than one blog post.  Inserting the above code into your index page will only tweet the title of your index page and that url.  We need to make some adjustments to the code….

Lets take a look at these changes.

  1. data-via=”SEOholistically” was generated by the generator at stage two “Recommend People to Follow (optional).  It will add in “via @SEOholistically” at the end of the tweet message, so don’t forget to change it to your own twitter account (not that I would mind if you didn’t).
  2. data-related=”copyblogger” I have just added in.  It would be generated automatically if I had filled in the second field of the “Recommend People to Follow (optional)” section.  Coppyblogger is nothing to do with me… but you should follow them anyway… good advice! Again, unless you want coppyblogger to be offered as a follow suggestion to everybody who uses the button, change it!
  3. data-url=”<?php the_permalink(); ?>” This is where we get into WordPress specific stuff. This tells twitter to take the url as being the individual blog post url rather than the page url.
  4. data-text=”<?php the_title(); ?>” This tells twitter to make the WordPress post title the content of the twitter post.

That is all there is to the code for the twitter tweet button if you are adding it to a WordPress blog.

So where do you put the Twitter code in WordPress?

You should add it to index.php and single.php. In this blog it looks like this (facebook button code removed for simplicity)


… so just search for <div class=’entry’> and put it in directly below that.


Do exactly the same thing as for single.php.

Why use the official Twitter Tweet Button?

You could use Tweetmeme or some other button… but the official button has a big seller for me.  Every time somebody uses it, it will offer up two suggestions of people to follow…. the two suggestions you provide using the data-via and data-related options.  It makes it much easier to gain more followers. That can’t be a bad thing!

About Ian Wortley

Ian is one of Irelands leading SEO consultants with over 8 years experience in the Irish market. Ian discovered his love of all things internet related in 2005 and has been living nearly exclusively online since then, causing much worry to friends and family, but getting great results for clients. Contact Ian: Phone: 01 6854806 Mobile: 086 3817149

One thought on “Official Twitter Tweet Button: Adding it to WordPress

  1. Pingback: Tweets that mention Official Twitter Tweet Button: Adding it to Wordpress » SEO Training --

Comments are closed.