Monday, November 30, 2020
Home Blogging How to Automatically Link Twitter Usernames in WordPress

How to Automatically Link Twitter Usernames in WordPress

Two years in the past, Twitter launched Twitter Anyplace API which made it very easy for us to say twitter usernames and have them be robotically linked to the best profile. It additionally allowed for stunning hovercards with more information. Sadly Twitter has determined to retire the Anyplace API on December sixth, 2012. Since we repeatedly point out person’s twitter handles in our submit content material, it solely made sense to provide you with a option to robotically hyperlink twitter usernames in WordPress. As a substitute of counting on a third-party script, we determined to write down a brief and easy plugin to maintain the job. On this article, we’ll present you robotically hyperlink twitter usernames in WordPress once you point out it after the @ signal like so: @GyanHi.

All it’s important to do is open a clean .php file and name it wpb-twitlinks.php. Then copy the code beneath and put it aside in there. Add the file into your plugins folder, and easily activate the plugin.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<?php
/*
Plugin Name: WPB Linkify Twitter Usernames
Description: Automatically link Twitter usernames in WordPress
Author: Syed Balkhi
Author URI: https://www.wpbeginner.com
*/
function twtreplace($content) {
    $twtreplace = preg_replace('/([^a-zA-Z0-9-_&])@([0-9a-zA-Z_]+)/',"$1<a href=\"http://twitter.com/$2\" target=\"_blank\" rel=\"nofollow\">@$2</a>",$content);
    return $twtreplace;
}
add_filter('the_content', 'twtreplace');  
//For Comments props to Julien Maury
add_filter('comment_text', 'twtreplace');
?>

Word, since we solely use this on our single submit and pages, we solely have the filter for the_content. You possibly can all the time lengthen this function to excerpts as effectively by including the next line:

1
add_filter('the_excerpt', 'twtreplace');

We aren’t saying that that is the one methodology that exists. There most likely are bunch of jQuery options obtainable. That is the quickest and best resolution in our opinion.

You May Also Like : What To Do When You Are Locked Out of WordPress Admin (wp-admin)

If you liked this article, make sure to hit the bell for getting our latest updates and share this article with your friends in every social media platforms.

1 COMMENT

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -

Most Popular

How to Signup for Godaddy Affiliate Program & Start Making Money

GoDaddy is likely one of the well-liked model names out there of area and web-hosting. They are well-liked for a numerous cause, and so they...

How To Start Selling Website on Flippa: A Beginner’s Guide To Success

If you may have been working on-line for lengthy and into Website flipping, Flippa is one identify that you need to have heard of. Flippa is a...

How to Fix Your Connection is Not Private Error (Site Owners Guide)

Are you seeing ‘Your connection is not private’ error in your WordPress web site? This is the error message you’ll see on Google Chrome. The...

How to Fix the WordPress White Page of Death (Step by Step)

The WordPress white page of dying is one of the most widespread WordPress errors. It can also be one of the most irritating ones as...

Recent Comments