Wordpress Plugin to Autolink Twitter

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Wordpress Plugin to Autolink Twitter

    I ain't sure if any of you are interested in wordpress plugins here but I believe many of you use wordpress and twitter. I just wanted to make a simple plugin which autolinks mentions in post or page to it's twitter profile and hashtags to twitter's search stream. There are other similar plugins in Wordpress plugin library but most of that brings more than this which I didn't want. Here's simple plugin:

    PHP Code:
    <?php
    /*
    Plugin Name: Autolink Twitter
    Plugin URI: http://ksg91.com
    Description: A simple plugin for wordpress, which automatically link mentions in post or page to twitter profiles and hashtags to search link. 
    Version: 0.8
    Author: Kishan Gor
    Author URI: http://ksg91.com
    License: GPL2
    */
    function autoLinkTwitter($contents)
    {
      
    //links mentions to the twitter profile
      
    $contents=preg_replace('/(\s)@([a-zA-Z0-9_]+)/',' <a href="http://twitter.com/\2">@\2</a>',$contents);
      
    //links hashtags to the twtitter search
      
    $contents=preg_replace('/(\s)#([a-zA-Z0-9_]+)/',' <a href="http://twitter.com/search?q=%23\2">#\2</a>',$contents);
      return 
    $contents;
    }
    //register our filter with wordpress 
    add_filter'the_content''autoLinkTwitter' );
    ?>
    How to Install?
    Put autolink-twitter.php file under your plugin directory and activate plugin from your admin menu.
    I haven't uploaded the plugin yet to wordpress.org library because I think very few people would be interested there.
    You may keep up with this plugin on my Git repository on github at https://github.com/ksg91/Autolink-Twitter
    Attached Files
    Follow me @ksg91 | My Blog: http://ksg91.com | Nokia Blog: http://NokiaTips.in
Working...
X