|

How to add a share on Twitter link to your WordPress Theme without Javascript

Today i will explain how to add Share on Twitter Link without adding JavaScript to your WordPress Theme.

We need a few things before we can start

  • A twitter username – The twitter username which will be displayed after your post content on twitter
  • Link to the publication you want to share – we can use the WordPress permalink:
<?php the_permalink(); ?>
  • The title which you want to include in you share link – we can add our post/page title with this simple php code:
<?php the_title(); ?>

This is very simple code and if you add this code you will share your post to twitter without using JavaScript

Add this code to your WordPress template were you want to appear the share link:

<a href="http://twitter.com/share?url=<?php the_permalink(); ?>&text=<?php the_title(); ?>&via=yourtwitterusername" title="Share this publication on Twitter" target="_blank">Share on Twitter</a>

All you need to do is to changeĀ yourtwitterusername with your real twitter username

Few tips to try:

Add Image in the Share on Twitter with this simple code:

<img src="your path to twitter logo image"/>

Now you will have a Share Button for Twitter without adding a JavaScript to your WordPress Theme

The code above can be added in your theme single.php file before orĀ  after the content



<a href="http://twitter.com/share?url=<?php the_permalink(); ?>&text=<?php the_title(); ?>&via=yourtwitterusername" title="Share this publication on Twitter" target="_blank">Share on Twitter</a>


Facebook Comments

Leave a Reply

Your email address will not be published. Required fields are marked *