Home / comment / Automatically link twitter usernames in posts
  • How to 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.

    ( click code to copy )

    wordpress snippet : PHP

    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');

    ( WordPress codex functions, hooks, in this snippet. )

    the_content, comment_text, add_filter,