I had a truckload of hits come to this site last night for my Hello Stumbler plugin, so I thought I would share with you how to make a plugin so you can publish it, stumble it, digg it and bask in your coding glory as it generates hits to your site!
I’ll use my Hello Stumbler plugin as a guide…(now re-done so you can see the code all proper like)
here’s the whole code
/*
Plugin Name: Hello Stumbler
Version: 1.1
Plugin URI: http://www.fiddyp.co.uk/2007/09/06/hello-stumbler-wordpress-plugin-for-stumbleupon-visitors/
Author: Andy Bailey
Author URI: http://www.fiddyp.co.uk
Description: Adds a message to request a thumbs up if post is seen via Stumbleupon. Just place hellostumbler(); in your single post template
*/
function hellostumbler(){
global $id;
$refer=$_SERVER['HTTP_REFERER'];
$title=the_title('','',false);
if ($refer=="http://www.stumbleupon.com/refer.php" && is_single()) {
echo "<strong> Thanks for Stumble-ing here!<br />Please give me a <a><img>thumbs up!</a></strong>";
}
}
?>
Step 1:
Add the comments to the top of your php file so WordPress knows it’s a plugin..
/* Plugin Name: Hello Stumbler Version: 1.0 Plugin URI: http://www.fiddyp.co.uk/2007/09/06/hello-stumbler-wordpress-plugin-for-stumbleupon-visitors/ Author: Andy Bailey Author URI: http://www.fiddyp.co.uk Description: Adds a message to request a thumbs up if post is seen via Stumbleupon. Just place hellostumbler(); in your single post template */
The plugin URL is important, don’t be tempted to just put a link to the root of your site or blog, it’s really annoying when a plugin misbehaves and you click on the plugin name within wordpress only to be sent to a site where you can’t find the reference to the actual plugin.
With mine, I make the post about the plugin and then go back to the source code and add the permalink, zip, upload and finally edit the post with the link to the download.
Step 2: Call the function a unique name
function hellostumbler() {
Make sure your plugin has a unique name or it will misbehave if it’s used on a blog that has a duplicate named plugin.
Step 3: Add the code that does the magic..
global $id;
$refer=$_SERVER['HTTP_REFERER'];
$title=the_title('','',false);
if ($refer=="http://www.stumbleupon.com/refer.php" && is_single()) {
echo "<strong> Thanks for Stumble-ing here!<br />Please give me a <a><img>thumbs up!</a></strong>";
}
}
?>
This is a simple little bit of code, lets analyze it line by line…
$refer=$_SERVER['HTTP_REFERER'];
all this does is find out what page the surfer came from and store it in the string $refer
global $id;
this assigns the variable $id as a global so you can use the value it has been given by the WordPress code
$title=the_title('','',false);
this assigns the title of the post to the variable $title by using the internal function of WordPress, whatever is between the ” , ” is what gets put before and after the title of the post, the false bit means return the title instead of printing it out on the blog.
if ($refer=="http://www.stumbleupon.com/refer.php" && is_single()) {
a conditional check, if the value in $refer is the same as the one given (in this case the referring page of Stumbleupon) AND the post is a single post page (It’s better to Stumble a post on it’s own rather than when it’s on the front page). If BOTH cases are true, do whatever is in the ‘{‘ curly brackets
echo "<strong> Thanks for Stumble-ing here!<br />Please give me a <a><img>thumbs up!</a></strong>";
echo means output to the page, putting html in the quotes writes html direct to the page. Then it’s a simple case of formatting the HTML so it works with the variables declared earlier. I’ll break this line down piece by piece..
-
echo "Thanks for Stumble-ing here! Please give me a
Just output some text for the surfer to see
- this is put into the source code so search engines and viewers of source can see where the next link comes from. Grabbed this from the Digg This plugin.
-
<a href='http://www.stumbleupon.com/submit?url=".get_permalink($id)."&title=$title'>
At the end of ?url= I close the echo quotes and use a dot (.) operator to add on the next bit that php sees, the get_permalink($id) just gets the link to the current post (it’s why we needed to have $id as global, WordPress has already declared what $id is) then we dot (.) a bit more echo output on to the end of that for the title name $title and close the html quotes with a single quote, and close the html a href bit with a >
-
<img>thumbs up!</a>";
echo out html code for displaying the SU icon, close the img HTML and put what text to display as link and then close the html. Finally, close the echo quotes and add a semicolon (;) to tell php we have finsihed the command (echo).
-
} } ?>
close the “if” check, close the function and finally end the PHP
Once you’ve done all that, upload the plugin to your wp-content/plugins/ directory and activate it, if all goes well, you should be able to add the output to anywhere on your page by calling the function name with
if (function_exists(hellostumbler)){hellostumbler();}
inserted into your template code.
This is what it looks like in action…

So, now there’s no reason why you can’t make a simple plugin to show a link to your facebook profile or add some code to show a Youtube video.
good luck, you’ll see that once you’ve made one plugin, you’ll want to make more and more!
You can download all the source code here : hello stumbler plugin











I am so bad actually when it comes to real coding but this is nice stuff!
I’m glad you like it Chase! your template coding is very nice, that’s something I want to be able to do better
Superb work Andy, I wish I could find a spare day to mess around with WP plugins
Thanks Mathew, I only discovered how to make plugins recently. Once you the comments in there, it’s just a case of making a function just like a normal php script function.. easy peasy!
Hi Andy,
that’s a good step by step tutorial. I have coded in php but never had chance to develop wordpress stuff other than theme (based on Kubric).
Hope to use this soon..
Jalaj’s last blog post..Drive Slowly : Google Ahead
I was surprised at how easy it was, it really is as simple as making a function and adding the correct comments to the top to make wordpress realize what it is.
I’ve only learned php from taking apart other peoples scripts so if you’ve played with themes and a bit of php then you should be able to knock one out in no time!
I might make a picture step by step tutorial for a hello world plugin and continue to expand it over a period of a few weeks, it might make a nice series for here.. hmmmm, I smell some draft posts being stored on my blog coming
this page comes up aparse error
René’s last blog post..Tut?s mummy on display for 1st Time?
thanks rene! fixed it now, I wrote this before I installed a plugin that can execute php code in a post..
should be ok now
Hi Andy -
I was surfing and came across your site when someone mentioned your Comment Luv Plugin and came to this post – re- creating a plugin . Although I am not a programmer in any way or form I realised I I would like to learn a little php .
Thanks for that great tutorial.
Take care have a great day
Hamant
Hamant Kevals last blog post..What’s The Best Way to get Traffic from Ebooks?
This is nice stuff. Explained with great detail. I’m a little unsure what version of WordPress this was written for? Has anything on plugin development changed since this was written considering we are now on 2.6 ?
Busby SEO Challenges last blog post..Website Hosting Options
Great Article and explained in really simpler meaner, i have one query regarding developing wp-plugin, is it advisable to use CURL php library in wp plugin ? which i am planning to use for one more my 1st wordpres pligun.
Blogsdnas last blog post..Customize Your Gmail Inbox Web Clips [Gmail New Feature]
Hey, thanks for the post, I’ve been looking all over for something to check the referring page via PHP, and the traffic from Stumbleupon is usually does wonders
Robin Bastien´s last blog post..Why content should become your baby
Pingback: بیش از 50 مرجع برای یادگیری و استفاده بهتر از وردپرس - تالار گفتمان تخصصی دانشگاه آزاد نیشابور
Pingback: Link FA | لینک فا » بیش از 50 مرجع برای یادگیری و استفاده بهتر از وردپرس
I’m been looking for this plugin for so long! I’m the first to admit that even if I like a site, I sometimes forget to give it a thumbs up for deserving websites. The other one that I like that is catching on is the retweet button at the bottom of posts.
Amazing detail about the code. You have inspired me to write a plugin tonight while I sip a beer! Cheers!