Ever since we published our WordPress guide for the Twitter Anywhere platform, we've received requests on how to automatically generate the text of tweets in the live tweet box. In this article, we will show you how you can add tweet text with Tinyurl in WordPress posts. We'll use the tinyurl API to generate a short URL for your post and display it with the text.
First open your theme functions.php file and paste the following codes:
function getTinyUrl ($ url) $ tinyurl = file_get_contents ("http://tinyurl.com/api-create.php?url=". $ url); devuelve $ tinyurl;
This function will allow us to generate tinyurls for your WordPress posts.
Then open your site footer.php and add the following code just above the closing body tag, OR you can add it in the header.php site before the closing head tag:
twttr.anywhere (onAnywhereLoad); funcion onAnywhereLoad (twitter) // configura el @Anywhere environment twitter ("# custom-tweetbox"). tweetBox (label: "Retweet:", defaultContent: "post-> ID;?> Reading: - ID)); echo $ turl;?> (a través de @wpbeginner) ", altura: 50, ancho: 480,); ;
Be sure to add your API key and switch (via @wpbeginner) to your own Twitter username. (If you want to know how to get a Twitter API, follow our Twitter Anywhere guide)
The last step is to open your single.php file and add the following code where you want it:
You would now have the live tweetbox on your post with a text displayed as:
Reading:Post Title - Tinyurl (via @wpbeginner)
If you don't want to show the box on your post, you can also try the plugin called Retweet Anywhere
Ruhanirabin