Once you’ve decided that you want to create a short URL for your blog, there are a few steps you need to go through in order to set it up properly.
This post will cover the following areas:
- Buy a short URL
- Sign up for bit.ly
- Add an A Record to point to bit.ly and verify it
- Download & install bit.ly Service WordPress plugin
- Use wp_get_shortlink in your theme (for sharing)
Buy a short URL
The best place to find urls is through http://domai.nr which offers you various combinations based on your search. It also shows if the domain is available which is awesome. For this site the short URL is http://crai.gd
Sign up for Bit.ly
Add an A Record to point to bit.ly and verify it
If you use http://iwantmyname.com to register your domain, they give you a wide selection of tools to use with your new domain; bit.ly being one of them. If you use a different provider then they may have something similar. Otherwise you’ll have to find where you can manually add a DNS entry and enter the details provided by bit.ly. If you’re using a custom URL you need to add an A Record but if you’re using a subdomain then you need to add a CNAME Record instead.
Once you’ve added the record you should be able to verify that through bit.ly.
Next you need to add a ‘tracking domain’ in order to get access to all of the analytics in bit.ly. It means the actual domain you’re linking to (e.g. http://craigmdennis.com not http://crai.gd). This also needs verifying by either a meta tag, custom named html file or creating a CNAME with a specific value. The same way you would verify Google Analytics. Again, bit.ly walks you through it.
Download and install ‘Bit.ly Service’ WordPress plugin
The best plugin for WordPress seems to be Bit.ly Service as it allows you to use your custom URL (it will override any choice you make in the dropdown). Others may work but do not explicitly say they work with custom URLs and may be out of date; relying instead on the old Bit.ly Pro service. You’ll need to get your bit.ly API key and username which you can get from the advanced tab in settings. Copy and paste that into the fields in the Bit.ly Service’s WordPress settings panel and you’re good to go!
Now the when you click on ‘get shortlink’ next to the URL of posts & pages, it should show your custom URL followed by the usual random characters. You can tweet that out and it will redirect to the post on your normal domain. Clever.
Use your custom URL in your theme
There are a few tutorials around for using bit.ly and sharing widgets like AddThis but if you just use the Tweet button (like this site) then you just need to replace the sharing URL with the shortened link.
You can do this by using the WordPress function
wp_get_shortlink(); with no parameters. The Bit.ly Service plugin filters the content of the function and replaces it with the custom bit.ly one. So when you call the function, it will retrieve your custom URL.
So for use with the twitter share button you just need to replace the data-url attribute with
<?php echo wp_get_shortlink(); ?> and when anyone clicks the link, it will show your brand new shiny custom URL.
Note: It’s worth mentioning that Twitter will actually convert all links to their t.co but it won’t affect bit.ly.