Simple Twitter Link



WordPress database error: [You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'AND b.name = 'Bug' AND a.category_id = b.id AND a.status <> 90 ORDER BY a.id' at line 1]
SELECT a.id AS 'ID', summary AS 'Description' FROM mantis_bug_table a, mantis_category_table b WHERE a.project_id = AND b.name = 'Bug' AND a.category_id = b.id AND a.status <> 90 ORDER BY a.id

WordPress database error: [You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'AND (b.name = 'Enhancement' OR b.name = 'Maintenance') AND a.category_id = b.id ' at line 1]
SELECT a.id AS 'ID', summary AS 'Description' FROM mantis_bug_table a, mantis_category_table b WHERE a.project_id = AND (b.name = 'Enhancement' OR b.name = 'Maintenance') AND a.category_id = b.id AND a.status <> 90 ORDER BY a.id

Simple Twitter Link displays a link allowing Twitter users to update their status with a link back to your post or page.

Description

From version 1.5 you must now install the Simple URL Shortener plugin for the URL shortening to work in this plugin

The code for Simple Twitter Link should be added to the bottom of appropriate post/page templates within your theme (and in the case of posts, within the loop).

Simple Twitter Link simply returns a URL - this URL is a link to Twitter with your post/page URL within it. Here's an example...

<a href="<?php simple_twitter_link(''); ?>">Send to Twitter</a>

This will display the text "Send to Twitter" on your page/post. However, when clicked on it will take you to your Twitter account and pre-fill in the status with "I'm currently reading xxx", where xxx will be the URL of the page/post that you just came from.

In the case of this example, no parameters were passed and, hence, a default sentence was passed to Twitter. If, however, you'd like to define your own Twitter text, then you simply pass this as a parameter. %url% must be specified within the sentence, as this tells Simple Twitter Link where you want the URL to go.

So, another example...

<a href="<?php simple_twitter_link('%url% is an excellent read'); ?>">Send to Twitter</a>

In this case the line "xxx is an excellent read" (again, where xxx is the URL of your page/post) will be passed to Twitter.

If you don't pass a parameter or miss out the %url% tag the default text will be used.

The following is an example of how it could be used, with a function_exists check so that it doesn't cause problems if the plugin is not active...

<?php if (function_exists('simple_twitter_link')) : ?>
<a href="<?php simple_twitter_link(''); ?>">Send to Twitter</a> <?php endif; ?>

You can also use an addition tag, %title%, which will show the post/page title in the Twitter text.

If you have the Simple URL Shortener plugin installed, you can also use a number of additional tags which will allow the URL to be shortened. Simple specify the name of the shortening service withing percentage signs within the Twitter text (this text will then be removed from the resultant output to Twitter). So, here is a further example...

<a href="<?php simple_twitter_link('%tr.im%Currently reading a blog post called "%title%" - %url%'); ?>">Send to Twitter</a>

This uses both the new %title% tag and also uses the tr.im shortening service to shorten the URL.

By default, the URL of the current post/page is used. If, however, you specify a URL as a second parameter then this will be used instead (useful if you wish to add a generic Twitter link to your sidebar, for instance). An example would be...

<a href="<?php simple_twitter_link('%tr.im%Currently reading a blog post called "%title%" - %url%','http://www.artiss.co.uk'); ?>">Send to Twitter</a>

From version 1.6 onwards you can also specify a number of further options via an optional third parameter. Each option is seperated by an ampersand and the following are valid...

cache= : Use this to turn off caching by specifying cache=no

apikey=, login=, password= : These allow optional URL shortening options to be specified (see the documentation for Simple URL Shortener for further details)

For example,

<a href="<?php simple_twitter_link('%bit.ly+key%Currently reading a blog post called "%title%" - %url%','','login=test&apikey=insertapikeyhere&cache=no'); ?>">Send to Twitter</a>

In this case you'd need to specify your own login and apikey for this to work.

There is an excellent article on how to use this plugin at Blogging With Success.

Installation

  1. Upload the entire simple-twitter-link folder to your wp-content/plugins/ directory.
  2. Activate the plugin through the 'Plugins' menu in WordPress.
  3. There is no options screen - configuration is done in your code.

Frequently Asked Questions

I get the error “cannot yet handle MBCS in html_entity_decode”

This is a known bug in PHP 4.

If other solutions do not work don’t request the “title” option in this plugin, as it is this that will trigger it.

How can I get help or request possible changes

Feel free to report any problems, or suggestions for enhancements, to me either via my contact form or by the plugins homepage.

User Comments & Reviews

"Just contacting to say Thanks for Simple Twitter Link. It is best one around for people who use custom social bookmarks."

"…a minimalist, excellent WordPress plugin called Simple Twitter Link" (Blogging Zest).

Changelog

1.0

  • Initial release

1.1

  • There is an additional template tag, %title%, which will show the post/page title in the Twitter text

1.2

  • Additional tags added to override the URL shortening service (defaults to TinyURL) - %is.gd%, %snipr%, %tr.im%

1.3

  • Added bit.ly to list of URL shortening services

1.4

  • Fixed issue with ampersands (and probably other characters) in the blog title causing linking issues
  • Added su.pr as another URL shortening service

1.5

  • Now using Simple URL Shortener plugin to provide URL shortening
  • Added new parameter that allows overriding of passed URL
  • Blog title corrected, using code from Simple Social Bookmarks plugin
  • Code tidied

1.6

  • Minor change to reduce chance of known PHP 4 error occuring.
  • Optional parameters can be passed for URL shortening purposes

Mantis Bug Tracker

Known Bugs

No bugs are currently recorded.

Planned Enhancements

No enhancements are currently planned.

Become master of latest technology with our testking SY0-201 online course. Download the testking 642-813 tutorials and testking 70-680 study guide for easy learning.

Delicious Digg Facebook LinkedIn Read It Later reddit StumbleUpon Twitter SeparatorEmail Google Translate PDF Online Print Friendly

Support Forum

Please use the forum for reporting any problems, queries or suggestions relating to this plugin.

10 Comments - ARCHIVE

  1. Helgi Hrafn Halldórsson says:

    Since Twitter mianly uses bit.ly, why not use that instead of tinyurl.com ? bit.ly is even 5 characters shorter :P

    *hint* $tinyurl = “http://bit.ly/api?url=”;

    Then again, it would be even cooler to detect if the revcanonical plugin is installed and use that as a shortening way for the url.

    plz let me know

    • David says:

      The plugin has now been updated with support for bit.ly – thanks for the suggestion.

      However, I don’t, at present, have plans to support the Revcanonical plugin.

  2. Helgi Hrafn Halldórsson says:

    I see that you use the $post variable inside the function. But you’re missing to declare at the top of the function global $post; :P

    The $post is empty if it is not mentioned to use the global $post variable.

  3. Sophia says:

    I installed your plugin WordPress 2.8 and pasted the code into the bottom of my single post template. I replaced the text “send to twitter” with an image. It crashed the page – resulted in a blank page whenever I viewed a single post. I had to uninstall it. Too bad, it looked like just what I needed.

    • David says:

      Don’t give up Sophia! I’ve happily used the plugin myself with an image, so it shouldn’t cause a problem. Can you send me the code you used, that didn’t appear to work?

  4. Jennifer says:

    I’m not sure why this is not working for me. It seems simple enough. I have it installed and activated. Do I need WordPress version 2.8.3 for Simple Twitter Link 1.3 to work? When I click the link, twitter opens up, the title is placed in the status update, but no url. I copied and pasted code from this site. Thanks so much for your help in advance. Can’t wait to use this awesome plugin!

    • David says:

      Hi Jennifer, what version of WordPress do you have? Any recent version should work.

      Please let me know the URL of your site, so that I can see what’s happening. Also, please send me (use my contact form!) the code that you’ve added to your site. With all that I should be able to get to the bottom of your problems.

  5. LJHarb says:

    Why do you require %bit.ly% and %url% to both be present? %bit.ly% should simply replace that occurrence with the bitly url – and if multiple services are present, they should all replace with their respective services.

    Also, using file_get_contents to get an external resource is a security risk, and it isn’t enabled on many servers for that reason. You should use curl instead (or at least check if file_get_contents can get http resources and use curl in that case).

    It would also be nice if there was a plugin options pane where I could add a shortening endpoint and service name/token so I can add my own services.

    Thanks!

    • David says:

      The %url% is a good one – this stemmed from the fact that the plugin originally just used the default URL shortening services and to change this I simply added an extra parameter.

      The only problem with modifying this would be backwards compatibility – I’m working on a new version of the plugin, though, so I can look at this.

      Re the curl idea – isn’t there an additional problem in that curl may not be active on some peoples servers? Happy to add it though as a fallback to file_get_contents.

      Options panel… no. My “Simple” range of plugins are designed to be just that, and that includes not providing option screens ;)

  6. LJHarb says:

    Sounds good – I’m capable of adding in my own service. However, even if there is no options pane – if there was any way to extend the service list that didn’t require modifying the plugin file that would be great. If I have to modify the file, every time there’s an update it requires surgery on my part.

    Personally I think it would be better to prefer curl, and fall back to file_get_contents if it isn’t present. Also, it would probably be good to use `strtolower(ini_get(‘allow_url_fopen’))===’off’ to check if file_get_contents can’t fetch urls, and if so (and curl’s not available), skip the shortening altogether.

5 Pingbacks/Trackbacks

  1. [...] Simple Twitter Link: A free plugin that generates short links for posts. We will need it for “Tweet This” button. [...]

  2. [...] Simple Twitter Link WordPress Plugin | Artiss.co.uk http://www.artiss.co.uk/simple-twitter-link – view page – cached Simple Twitter Link displays a link allowing Twitter users to update their status with a link back to your post or page. — From the page [...]

  3. [...] Simple Twitter Link – This is not a widget but rather something to integrate on your wordpress [...]

  4. 35 Wordpress Twitter Plugins | Tommy Pratama wrote:

    [...] Simple Twitter Link – This is not a widget but rather something to integrate on your wordpress [...]