Code To Share Current Page URL or Link To Twitter

Simple Twitter share current URL or link methods.

Twitter Share Page URL Code

So you want to add a link or button to share your current page URL or a static link to twitter? Of course Twitter provides a few resources for this which are ugly to say the least, there are also third-party services available such as AddThis – not to mention if you are using WordPress there are loads of plugins to get the job done. But we are going to look at a few very simple code snippets that will get the job done that are totally light-weight and painless.

Show Me The Twitter Share Code

Alrighty, let’s get to it. First up let’s look at the standard URL structure Twitter uses that will make a URL or link sharable.

Now, let’s make this a simple share link that can be embedded into your website. Obviously you will want to change to your actual website or page.

<a href="" target="_blank">Share On Twitter!</a>

Creating A Twitter Share Button Using A Image

So, if you want to use an image as a button for your share code, it would look something like this:

<a href="" target="_blank"><img src="" /></a>

The above code is recommended simply because well, visual buttons have a better conversion ratio. An example of what your Twitter share image based button could look like is below, go ahead and give it a try:

share twitter button

What About Sharing The Current Page Using WordPress?

No problem, this can be done easily if we throw some PHP into the mix, open your specific template or WordPress PHP file to create a dynamic Twitter share link that will automatically set the current page being used for sharing. Your code will look like:

<a href="<?php echo get_permalink($post->ID);?>" target="_blank">Share On Twitter!</a>

We hope you found this article helpful, feel free to share your thoughts, ideas, or examples in the comments.

Back to Blog

2 Responses to “Code To Share Current Page URL or Link To Twitter”

Leave a Reply

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