Wordpress Plugin to Autolink Twitter

Started on the old forum in January 2012 · view the original in the archive · old links redirect here

No replies · 618 views · started 14 years ago · 1 min read

ksg91 Developer · 162 posts #1

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
/*
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

Follow me @ksg91 | My Blog: http://ksg91.com | Nokia Blog: http://NokiaTips.in

Attachments: autolink-twitter.zip

Sign in to reply.

Similar topics

Keyboard shortcuts

g f
Go to forums
g h
Go to your feed
g m
Go to messages
r
Reply (in a topic)
/
Search
j
Next post
k
Previous post
?
This list
Ctrl/⌘ + Enter
Send what you are writing
Ctrl/⌘ + B / I
Bold / italic while writing
Esc
Close