Linking Twitter usernames on WordPress posts automatically
Learn how to link Twitter usernames to its respective Twitter page automatically from WordPress contents. This article shows how to connect to Twitter pages using a short code snippet.
Learn how to use a short code snippet to autolink Twitter mentions on WordPress posts to their respective pages. This article shows you how to add a short PHP code snippet to functions.php to autolink Twitter user names.
Configuring autolink for Twitter usernames in WordPress articles
Follow the steps below to edit your Theme setting file:
-
Log in to your WordPress site with an administrator account.
-
On the Dashboard in the left sidebar, click Appearance, and then click Theme Editor:
Important
You will not be able to roll back to your earlier Theme configuration after any edits. Save the Theme files before proceeding with the modifications.
- On the Theme Editor, select the Theme you want to edit from the dropdown:
-
Click on the file named "functions.php"
-
Copy and paste the following code block into functions.php.
function add_twitter_links($content) {
return preg_replace('/([^a-zA-Z0-9-_&])@([0-9a-zA-Z_]+)/', "$1@$2", $content);
}
add_filter('the_content', 'add_twitter_links');
add_filter('comment_text', 'add_twitter_links');
- Save the file and exit the editor.
More Information
For more information about the please visit the following link: https://wordpress.org/plugins/theme-editor/
Related Articles
Updated 3 days ago