Arquivo da tag: app twtter

Show a Retweet Button with a Counter with Each Post

Show a Retweet Button with a Counter with Each Post

While a “Tweet This!” button is a great way to encourage user engagement, an even better tool is a retweet button with a counter. This button allows for easy sharing of a website’s content to the social network, and it will keep count of how many people have done so. The code snippet is pretty brief, and looks like this:

Once customized with the Twitter username of the website’s administrator, it will begin keeping count of all the post’s retweets on the popular social network.

Display the Latest Tweet as an Image

Display the Latest Tweet as an Image

A service known as TwitSig is actually capable of reading an account’s tweets and then processing them into an image that can be included in forum signatures, emails, and WordPress templates. This is a great way to show tweets without having their content impact the site’s SEO with major search engines. To do this, simply go to and sign up according to the website’s instructions.

Then, anywhere within WordPress, add the following code:

Image of Tweets

Create a Page Specifically Used to Display Tweets

Create a Page Specifically Used to Display Tweets

Sometimes, Twitter becomes so central to the success of a website that it deserves its own WordPress page. While this might seem a bit intimidating to accomplish at first, it’s actually very easy. WordPress is simply told to read the Twitter account’s RSS feed and print its content into the page.

To accomplish this, create a new PHP template file called tweets.php and paste the following code into that file:

< ?php /* Template Name: A Page for Tweets */get_header();include_once(ABSPATH.WPINC.'/rss.php'); wp_rss('', 35);get_sidebar(); get_footer();?>

The template above will pull in the existing header, footer, and sidebar, largely completing the site’s design. It will fill that design in with the last 35 tweets that a user posted. Be sure to edit the RSS feed URL to reflect the proper Twitter account before saving the file.

Automatically Create Short URLs for Posts in Tweets

Automatically Create Short URLs for Posts in Tweets

With a simple hack to the theme-specific “functions.php” file, WordPress can automatically generate and display short URLs that are perfect for inclusion in Tweets. This hack uses an existing URL shortening service, and comes in two parts. The first part, placed into the functions file, looks like the example below:

function makeBitly($url) {
$tinyurl = file_get_contents(“”.$url);
return $bitly;

With that new function added to “functions.php,” a second piece of code must be added to the website’s template in order to display the created URL. That line of PHP code must be placed within the WordPress Loop, and it looks like the following:

< ?php $burl = makeBitly(get_permalink($post->ID)); echo ‘The short URL for this post: < a href="'.$burl.'" >‘.$burl.’< /a >‘ ? >

Detect Visitors From Twitter

Detect Visitors From Twitter

Much like some websites detect visitors from search engines and greet them in a unique way, Twitter visitors can be automatically detected as well. This is done in almost the exact same manner as search engine detections, using conditional PHP code to check for a visitor’s referral agent and greet them accordingly. here’s how it looks:

< ?php if (strpos("",$_SERVER[HTTP_REFERER])==0) { echo "Hey, Twitter enthusiast! We're glad you're here. If you like what you see, be sure to Tweet about it and follow our account!"; } ?>

This code can be placed wherever the greeting should be displayed. Because it is entirely self-contained, there are no modifications necessary to the “functions.php” file or any other files on the FTP server. Only the template files need to be altered.

Display the Latest Tweets from Multiple Authors

Display the Latest Tweets from Multiple Authors

The code mentioned in the above hack can actually be slightly modified so that it can support displaying the latest tweets from multiple users. The modification is rather simple, and still results in a snippet of self-contained PHP code. Place the following lines of code into a template file where the tweets should appear:

< ?php $usernames = "Profile1 Profile2 Profile3 Profile4"; // Usernames go here, separated by a space. $limit = "5"; // Define the maximum number of tweets to show $show = 1; // Change to 0 if account usernames should not be shown, leave set to 1 if they should be $prefix = "Our Latest Tweets"; // A prefix or heading for the tweets $prefix_sub = ""; //Prefix for each individual tweet $wedge = ""; // Separator between tweets $suffix_sub = "
“; // Appended to the end of every tweet
$suffix = “”; // This section of code will be added at the end of the entire list of tweets

function parse_feed($usernames, $limit, $show, $prefix_sub, $wedge, $suffix_sub) {

$usernames = str_replace(” “, “+OR+from%3A”, $usernames);
$feed = “” . $usernames . “&rpp=” . $limit;
$feed = file_get_contents($feed);
$feed = str_replace(“&”, “&”, $feed);
$feed = str_replace(“< ", "<", $feed); $feed = str_replace(">“, “>”, $feed);
$clean = explode(““, $feed);
$amount = count($clean) – 1;

for ($i = 1; $i < = $amount; $i++) {$entry_close = explode("“, $clean[$i]);
$clean_content_1 = explode(““, $entry_close[0]);
$clean_content = explode(“
“, $clean_content_1[1]);
$clean_name_2 = explode(““, $entry_close[0]);
$clean_name_1 = explode(“(“, $clean_name_2[1]);
$clean_name = explode(“)
“, $clean_name_1[1]);
$clean_uri_1 = explode(““, $entry_close[0]);
$clean_uri = explode(“
“, $clean_uri_1[1]);

echo $prefix_sub;

if ($show == 1) { echo “” . $clean_name[0] . “” . $wedge; }
echo $clean_content[0];
echo $suffix_sub;
echo $prefix;
parse_feed($usernames, $limit, $show, $prefix_sub, $wedge, $suffix_sub);
echo $suffix;

Using the prefixes, the sub-prefixes, and the wedge variable, it’s possible to customize the above code pretty easily and make sure that it fits into any context within in an existing website’s design. Simply list all relevant Twitter usernames, separated by a space, and each will show their latest tweet within the defined limit set in the code.

Display the Latest Tweet on the WordPress Site

Display the Latest Tweet on the WordPress Site

To display the latest tweet anywhere on the WordPress site, including the header, sidebar, footer, or even the main content area, a simple PHP snippet can be used. This code is entirely self-contained, and can be placed directly into a template file. Here’s how it looks:

< ?php $username = "YourTwitterUsername"; // Put your username here. $prefix = "My Latest Tweet"; // Any text that goes before the tweet itself. $suffix = ""; // Any text that should be placed directly after the tweet. $feed = "" . $username . "&rpp=1";function parse_feed($feed) { $stepOne = explode("“, $feed);
$stepTwo = explode(“”, $stepOne[1]);
$tweet = $stepTwo[0];
$tweet = str_replace(“<“, “< ", $tweet); $tweet = str_replace(">", ">“, $tweet);
return $tweet;

$twitterFeed = file_get_contents($feed);
echo stripslashes($prefix) . parse_feed($twitterFeed) . stripslashes($suffix);

The PHP snippet above uses the built-in RSS parsing engine that ships with WordPress. It uses the “username” variable to read an account’s RSS feed, and posts the latest tweet in that feed to the website. The prefix and suffix areas allow the tweet to be placed into context, all within the self-contained PHP code.

Display the Website's Total Number of Twitter Followers

Display the Website’s Total Number of Twitter Followers

In order to create an air of popularity, it might be a good idea to show how many people follow the blog’s Twitter account. This method could also be used to show how many people follow a specific author’s account, thereby encouraging new visitors to log on to Twitter and do the same. This involves a relatively long function within the theme-specific functions.php file, as well as a small piece of PHP code in any of the template files where followers should be displayed. The function looks like this example:

function string_getInsertedString($long_string,$short_string,$is_html=false){
if($short_string>=strlen($long_string))return false;
return string_getInsertedString($html,$html2,true);

function getTwitterFollowers($username){
$x = file_get_contents(“”.$username);
$doc = new DomDocument;
$ele = $doc->getElementById(‘follower_count’);
$innerHTML=preg_replace(‘/^< [^>]*>(.*)< [^>]*>$/’,”1″,DOMElement_getOuterHTML($doc,$ele));
return $innerHTML;

With this code placed into the theme-specific functions.php file, a username can be supplied by an external line of PHP code in order to return a specific account’s followers. That’s done by placing the following code into one or more of the current theme’s template files:

We have < ?php echo getTwitterFollowers("YourTwitterUserName")." followers on Twitter"; ?>.

Create a "Tweet This" Button to Be Displayed with Posts

Create a “Tweet This” Button to Be Displayed with Posts

One of the best ways to promote website content and encourage it to go viral is to allow readers to share each post via Twitter. This is done by placing a relatively basic line of code within the standard WordPress Loop, enabling users to create a tweet that automatically links to the post’s permalink. Here’s how it looks in most cases:

Tags Autor

Create a "Tweet This" Button to Be Displayed with Posts