Automatically link twitter usernames in posts

Excellent snippet by Paul Underwood that will automatically link twitter usernames in your posts. This snippet will look for text like @wpsnipp and convert it to <a href="http://twitter.com/wpsnipp">@wpsnipp</a> something I'm sure many of you will find useful.

Code Snippet:

function content_twitter_mention($content) {
return preg_replace('/([^a-zA-Z0-9-_&])@([0-9a-zA-Z_]+)/', “$1@$2“, $content);

add_filter('the_content', 'content_twitter_mention');
add_filter('comment_text', 'content_twitter_mention');

Comments  Leave a Reply

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our privacy policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

WordPress Launch Checklist

The Ultimate WordPress Launch Checklist

We've compiled all the essential checklist items for your next WordPress website launch into one handy ebook.
Yes, Send Me the Free eBook!