Easy way to create WordPress bit.ly shorten urls

Such URLs helps you to save sharing twitter chars. Use it in Your theme
  • Home
  • Articles
  • Easy way to create WordPress bit.ly shorten urls
Share this post and Be Happy!

Every (WordPress) blogger wants to be shared by users via social buttons. But one of the most social network Twitter has limit for 140 characters including your URL. And what you need to do if your site has long domain? Anyway, your post url will have a lot of characters, so other twitter text will loose. To save Twitter characters for text you can use short URL services. One of the most one is bit.ly: free and easy to use service. Your shortener URL will looks like http://bit.ly/sOmEhAsH.

1. Bit.ly registration

Go to bitly.com

Registration at bit.ly

bitly form

2. Get OAuth2 token

Since 2011 Bit.ly uses more secure API via OAuth2 authorize protocol. OAuth uses only their tokens for authorization. Lets get our token!

Go to Generic Access Token page.

OAuth token bit-ly

Enter your bit.ly account password and click Generate token

OAuth token

Copy and remember the hash below Generic Access Token, this is your personal token for bit.ly service

3. Coding

Lets create a simple function in functions.php of your theme that will return a bitly shorten URL for your post URL.

This is it. Now you can use the function lenslider_bitlyshorten($post_id_or_empty) to return bitly URL.

4. Twitter WordPress code

This example is for HTML code inside WP Loop, that means global WordPress variable $post is available.

4.1 Twitter JS-init in header (<head> tag) or footer (before </body> tag)

4.2 Twitter share button code

The code is for a small twitter share button with horizontal counter:

Share this post and Be Happy!
About The Author

Hi, I'm Igor, one of many PHP/WordPress developers. I'll try to share here WordPress news and development ideas/hacks here. I'll be glad if you share my texts via socials. Have a good day!

Leave a Reply

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

× 7 = sixty three

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">

© 2013 LenSlider. All rights reserved.