Check out the Latest Articles:

twitter-logoHey guys, this code will let you automatically tweet your latest blog post to twitter. Lol didn’t understand? What I mean to say is each time you write a new post, the following PHP code will automatically update your twitter timeline with that post. Cool! keep reading..

Open up the functions.php file in your current theme and simple add the following code. Dont forget to change the username and password in the code. Save the file. Thats it, you’re done.

Plugin coming tomorrow for those who are scared to mess up with the theme, since its already 12AM here and I want to sleep. Oh yes, here is the code lol

for those who are

function twitterit($post_id) {
$username = "atif089";      // write your twitter username
$password = "abcdefg";      // write your twitter password here
$post = get_post($post_id);

$title = get_the_title($post->ID);
$post_permalink = get_permalink($post->ID);

$ch = curl_init();      // initialize cURL
// lets make a tinyurl of your post
curl_setopt($ch, CURLOPT_URL, "http://tinyurl.com/api-create.php?url=$post_permalink");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$tinyurl = curl_exec($ch);  // get tinyurl of permalink

// now publish it to twitter
curl_setopt($ch, CURLOPT_URL, "http://twitter.com/statuses/update.xml");
curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($ch, CURLOPT_POSTFIELDS, "status=$title $tinyurl");
$buf = curl_exec($ch);

//echo $buf;
curl_close($ch);
}

add_action('publish_post','twitterit',10,2);

Related posts:

  1. Add content after First Post
  2. How to Insert content after each post in WordPress
  3. How to create a WordPress Theme
  4. WordPress Plugin – RSS Post Editor
  5. How to Create Post Accordions in WordPress


  1. It‘s quite in here! Why not leave a response?