• Home
  • Archive
  • Tools
  • Contact Us

The Customize Windows

Technology Journal

  • Cloud Computing
  • Computer
  • Digital Photography
  • Windows 7
  • Archive
  • Cloud Computing
  • Virtualization
  • Computer and Internet
  • Digital Photography
  • Android
  • Sysadmin
  • Electronics
  • Big Data
  • Virtualization
  • Downloads
  • Web Development
  • Apple
  • Android
Advertisement
You are here:Home » Twitter Hashtag, @ and Inline Tweet in WordPress

By Abhishek Ghosh August 26, 2014 5:37 pm Updated on June 1, 2017

Twitter Hashtag, @ and Inline Tweet in WordPress

Advertisement

We can integrate Twitter Hashtag, @ and Inline Tweet in WordPress in several ways. It matters how you want to use the features in your blog. With time, Twitter API has undergone a huge change, possibly you will want to read about hashtag system, Twitter Hashtag and Twitter Tricks and Cheat Sheet With New API guide to get used with Twitter specific stuffs. Plugins are there, we will definitely mention but one must know the existence of non-WordPress Plugin ways to integration. Essentially, using lot of plugins can make your database quite pathetic. There are some “paid Plugins” too, although buying such is not recommended as they will try to use some API to authenticate your item which might compromise your security.

 

Twitter Hashtag, @ and Inline Tweet in WordPress : Let Us Start With Easiest Example

 

We can not use @anywhere platform anymore, its old and retired. With PHP preg replace, we can simply do many works :

Vim
1
2
3
4
5
6
7
8
9
// Display Twitter @username links
function tweet($text) {
       $text = preg_replace('/([\.|\,|\:|\¡|\¿|\>|\{|\(]?)@{1}(\w*)([\.|\,|\:|\!|\?|\>|\}|\)]?)\s/i', "$1<a href=\"https://twitter.com/$2\" class=\"tweet-username\">@$2</a>$3 ", $text);
       $text = preg_replace('/([\.|\,|\:|\¡|\¿|\>|\{|\(]?)#{1}(\w*)([\.|\,|\:|\!|\?|\>|\}|\)]?)\s/i', "$1<a href=\"https://search.twitter.com/search?q=%23$2\" class=\"tweet-hashtag\">#$2</a>$3 ", $text);
       return $text;
}    
// Replace content and excerpt
add_filter('the_content', 'tweet', 9);
add_filter('the_excerpt', 'tweet', 9);

If we sanitize and add it on current Theme or Child Theme’s functions.php file, it will automatically link from text. But this is a hardcoded HTML link towards Twitter which you might not link. Possibly you know that, if @AbhishekCTRL is the username, we can reach it via hashtag too. These are same links :

Advertisement

---

Vim
1
2
3
https://twitter.com/#!/AbhishekCTRL
# equivalent to
https://twitter.com/AbhishekCTRL

Now, how we can create an inline Twitter Retweet Button, this is called Twitter Intent :

Vim
1
https://dev.twitter.com/docs/intents#retweet-intent

If you manually want to add a RT button, only inserting this after modification is enough :

Vim
1
2
3
<a href="https://twitter.com/intent/retweet?tweet_id=504205447910281216" class="retweet" style="display:inline-block;font-family:georgia,serif;font-size:12px;color:#000;text-decoration:none;padding:1px 5px;border:1px solid #ccc;border-radius:3px;background-color:#ddd;background:linear-gradient(to bottom, #f6f6f6, #ddd)">Retweet</a>
<style>.retweet:hover{opacity:0.9}</style>
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wks");</script>

Here is the thing when I pasted in text mode in WordPress :

Retweet

Twitter-Hashtag-Inline-Tweet-in-WordPress

Indeed, I used only :

Vim
1
2
<a href="https://twitter.com/intent/retweet?tweet_id=504205447910281216" class="retweet" style="display:inline-block;font-family:georgia,serif;font-size:12px;color:#000;text-decoration:none;padding:1px 5px;border:1px solid #ccc;border-radius:3px;background-color:#ddd;background:linear-gradient(to bottom, #f6f6f6, #ddd)">Retweet</a>
<style>.retweet:hover{opacity:0.9}</style>

The Javascript is already loaded by the social sharing button. By the way, I grabbed the ID from here:

Vim
1
https://twitter.com/AbhishekCTRL/status/504205447910281216

Now, we can modify and exclude all css style – Retweet – click it, it will give you a nice Javascript popup! Quite easy code :

Vim
1
<a href="https://twitter.com/intent/retweet?tweet_id=504205447910281216" class="retweet">Retweet</a>

As the class="retweet" is there, it will work. Unless you are a fool, you will not use a Twitter Plugin for these simple usages. Oho, understood, you are not liking RT to the same stuff, you want a sentence to included to RT, right? You can retweet our Install WordPress with Nginx on Rackspace Cloud Server guide! Do it!. I retrieved it via an old post. Anyway, here is the thing :

Vim
1
<a href="https://twitter.com/intent/tweet?original_referer=https%3A%2F%2Fthecustomizewindows.com%2F2014%2F08%2Finstall-wordpress-nginx-rackspace-cloud-server%2F&text=Install%20WordPress%20with%20Nginx%20on%20Rackspace%20Cloud%20Server&tw_p=tweetbutton&url=http%3A%2F%2Fbit.ly%2F1sLQugH&via=AbhishekCTRL" class="retweet">You can retweet our Install WordPress with Nginx on Rackspace Cloud Server guide! Do it!</a>

Very easy. Look at this broken explanation :

Vim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# constant
<a href="https://twitter.com/intent/tweet?
# original referrer is the safe url of the post
original_referer=https%3A%2F%2Fthecustomizewindows.com%2F2014%2F08%2Finstall-wordpress-nginx-rackspace-cloud-server%2F
# &text is what will be shared
&text=Install%20WordPress%20with%20Nginx%20on%20Rackspace%20Cloud%20Server
# source is tweet button, its a hack
&tw_p=tweetbutton
# this is url shortener's url
&url=http%3A%2F%2Fbit.ly%2F1sLQugH
# via is me
&via=AbhishekCTRL"
# class is to force the javascript
class="retweet">
# my custom text
You can retweet our Install WordPress with Nginx on Rackspace Cloud Server guide! Do it!
# ended the hyperlink
</a>

The complex looking url is nothing but encoded url, you can read Percent-encoding and URL Encode/Decode to know more. You can retrieve an url in WordPress using the_permalink() function. That will make it automated. I will make it better in near future in fully handed way without using any plugin. I guess you have no complain now. Hashtag will get auto linked with that PHP script if you want. It is more easy – just a hyperlink, in case you want to manually do to prevent unwanted stuffs.

 

Twitter Hashtag, @ and Inline Tweet in WordPress : Middle With Javascript

 

In case you want auto link via Javascript. There is also method. First create a Twitter Application with your domain name – do not install those stuffs, only create the Twitter Application. You will get an API. Load this Javascript at header :

Vim
1
2
<a href="https://twitter.com/share" class="twitter-share-button" data-via="AbhishekCTRL" data-related="AbhishekCTRL" data-hashtags="AbhishekGhosh">Tweet</a>
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+'://platform.twitter.com/widgets.js';fjs.parentNode.insertBefore(js,fjs);}}(document, 'script', 'twitter-wks');</script>

Unfortunately this automatic thing has limitations, despite it can work on all pages (no need to bother about the url). In action :

Tweet

Disadvantage is that, we can not reuse it for linking as many as we will love, plus if the person hits backspace, the session will get terminated.

 

Twitter Hashtag, @ and Inline Tweet in WordPress : End With Complicated Plugins

 

There are some plugins :

Vim
1
2
http://wordpress.org/plugins/evergreen-post-tweeter/
http://wordpress.org/plugins/twitter-tools/

 

Pure HTML, No Javascript, With Icon Font Twitter Hashtag, @ and Inline Tweet in WordPress

 

Here is a real working example :

Tweet this real working link .

We used this HTML :

Vim
1
<a class="twitter" href="http://twitter.com/home/?status=Twitter Hashtag, @ and Inline Tweet in WordPress https://thecustomizewindows.com/2014/08/integrate-twitter-hashtag-and-inline-tweet-in-wordpress/ by @AbhishekCTRL" target="_blank" title="Click to tweet this">Tweet this real working link <i class="icon-twitter"></i></a>

As icon-font is already loaded on this webpage with CSS for other Twitter icon, we need not to load anything more. You can perform search on our website with related keywords for any required helpful in-depth guide.

Tagged With include hashtags in wordpress excerpt , inline tweet , wordpress twitter hashtag
Facebook Twitter Pinterest

Abhishek Ghosh

About Abhishek Ghosh

Abhishek Ghosh is a Businessman, Surgeon, Author and Blogger. You can keep touch with him on Twitter - @AbhishekCTRL.

Here’s what we’ve got for you which might like :

Articles Related to Twitter Hashtag, @ and Inline Tweet in WordPress

  • Retweetable Blockquote in WordPress Posts With CSS, Js

    We Can Create Retweetable Blockquote in WordPress Posts With CSS, Js For Special Articles. Embedding the CSS and Javascript in Post Will Do the Job.

  • Hashtag in Twitter : Basics to API for Twitter Hashtag

    Hashtag in Twitter Has Many Functions Which Are Usually Unknown. Here is detailed guide on using Hashtag on Twitter by any level of user.

  • Create Inline Tweet in WordPress

    Create Inline Tweet in WordPress Inline To Simply Create Hyperlinks to Share Content on twitter With a Twitter CSS Icon Font With Extra Load.

  • Hashtag in Facebook : Basics to API for Facebook Hashtag

    Hashtag in Facebook Has Many Functions Which Are Usually Unknown. Here is detailed guide on using Hashtag on Facebook by any level of user.

performing a search on this website can help you. Also, we have YouTube Videos.

Take The Conversation Further ...

We'd love to know your thoughts on this article.
Meet the Author over on Twitter to join the conversation right now!

If you want to Advertise on our Article or want a Sponsored Article, you are invited to Contact us.

Contact Us

Subscribe To Our Free Newsletter

Get new posts by email:

Please Confirm the Subscription When Approval Email Will Arrive in Your Email Inbox as Second Step.

Search this website…

 

Popular Articles

Our Homepage is best place to find popular articles!

Here Are Some Good to Read Articles :

  • Cloud Computing Service Models
  • What is Cloud Computing?
  • Cloud Computing and Social Networks in Mobile Space
  • ARM Processor Architecture
  • What Camera Mode to Choose
  • Indispensable MySQL queries for custom fields in WordPress
  • Windows 7 Speech Recognition Scripting Related Tutorials

Social Networks

  • Pinterest (24.3K Followers)
  • Twitter (5.8k Followers)
  • Facebook (5.7k Followers)
  • LinkedIn (3.7k Followers)
  • YouTube (1.3k Followers)
  • GitHub (Repository)
  • GitHub (Gists)
Looking to publish sponsored article on our website?

Contact us

Recent Posts

  • Market Segmentation in BriefSeptember 20, 2023
  • What is Booting?September 18, 2023
  • What is ncurses?September 16, 2023
  • What is JTAG in Electronics?September 15, 2023
  • iPhone 15 Pro Max Vs Samsung Galaxy S22/S23 UltraSeptember 14, 2023
PC users can consult Corrine Chorney for Security.

Want to know more about us?

Read Notability and Mentions & Our Setup.

Copyright © 2023 - The Customize Windows | dESIGNed by The Customize Windows

Copyright  · Privacy Policy  · Advertising Policy  · Terms of Service  · Refund Policy