Unless you’re living under a rock (or you live in Tasmania), you’re probably already well aware that PayPal provides donate buttons for your website. This post details how to display a text link or button that will send visitors to your PayPal donate page.
Personally, I’m not a fan of using donate buttons for any purpose other than sending people to a genuine charity. I cringe every time I see a Donate button on a website that’s also plastered with advertising and other means of generating income. The fact the income streams are combined isn’t what bothers me; it’s that I believe that if you’re interested in deriving an income from an online service, there are far more effective and less intrusive ways of doing so than asking your visitors for cash. Member areas, digest subscriptions and other types of protected member-only content are a far more effective (and ethical?) means of establishing a recurring income.
That said, here’s some shortcode that can be used on a WordPress blog to render a text donation link or image that will redirect to PayPal.
PayPal Text Link Shortcode
function paypal_donate_shortcode($atts) {
extract(shortcode_atts(array(
'text' => 'Make a donation with PayPal',
'account' => 'you@youremail.com', // Your PayPal email
'itemname' => '', // replace
'itemnumber' => '', // replace
'amount' => '', // default donation
), $atts));
global $post;
global $authordata;
$blogName = get_bloginfo('name');
$via = str_replace(" ","+",$post->post_title);
if (!$itemname) $itemname = str_replace(" ","+","$blogName");
if (!$itemnumber) $itemnumber = str_replace(" ","+",$authordata->display_name);
return '<a class="donatepaypal" href="https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business='.$account.'&item_name='.$itemname.'&item_number=Donation+for+'.$itemnumber.'+via+'.$via.'&amount='.$amount.'¤cy_code=USD">'.$text.'</a>';
}
add_shortcode('donate', 'paypal_donate_shortcode');
Available shortcode parameters
text – Text that will link to PayPal. Defaults to “Make a donation with PayPal”.
account – Email attached to your PayPal account.
itemname & itemnumber – itemname & itemnumber are ‘essentially’ a category and sub-category used for referencing the source of nature of the donation. If not defined, itemname will display your ‘blog name’ and itemnumber will render “Donation for [author_name] via [Blog Post Name]” (see images below for examples).
amount – default amount to be paid. Will prompt for a value if not defined. Not required.
Example shortcode:
This shortcode: [donate text=”will output this”], will output this. Please don’t make a real donation!
If the donation value isn’t defined, it will direct you to a PayPal screen that looks like this:
Text Enlarged. Will output what is defined in your shortcode
If the donation value is defined, it will direct you to a PayPal screen that looks like this:
PayPal Donation value defined in shortcode
Example shortcode to render a donation value of $25 is as follows: [donate text=”donate here” amount=”25″].
You can obviously style any of the text links however you wish.
PayPal Image Link Shortcode
PayPal image links are far more popular than the text link I’ve provided above. If you’re only going to use a single instance of a PayPal image, you may want to consider simply using the online tool provided on the PayPal website. If, however, you want to retain control over multiple buttons in different locations… or you want to style them individually (for different authors, for example), then shortcode is almost certainly your best option.
Example output from the PayPal online tool
I originally wrote shortcode to emulate the form code provided on the PayPal website before I decided it was simply easier to simple create the same shortcode as above but reference an image. So, the shortcode of [donateimage] will output the following:

As always, paste the following code into your theme’s functions.php file or shortcode plugin.
function paypal_image_shortcode($atts) {
extract(shortcode_atts(array(
'account' => 'you@youremail.com', // Your PayPal email
'itemname' => '', // replace
'itemnumber' => '', // replace
'amount' => '', // default donation
'image' => 'http://www.internoetics.com/images/btn_donate_LG.gif',
), $atts));
global $post;
global $authordata;
$blogName = get_bloginfo('name');
$via = str_replace(" ","+",$post->post_title);
if (!$itemname) $itemname = str_replace(" ","+","$blogName");
if (!$itemnumber) $itemnumber = str_replace(" ","+",$authordata->display_name);
return '<a href= "https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business='.$account.'&item_name='.$itemname.'&item_number=Donation+for+'.$itemnumber.'+via+'.$via.'&amount='.$amount.'¤cy_code=USD"><img src='.$image.' border="0"></a>';
}
add_shortcode('donateimage', 'paypal_image_shortcode');
The shortcode parameters are the same as above except that we must now define an image. Don’t use the image from my server! Whatever image you define in your shortcode will be rendered by default.
If you’re interested in reading more about the buttons, values and/or URL structure of PayPal donation links and buttons, you can do so on the PayPal website.
|
|
Download: PayPal Donation Shortcode |
If you liked this article, you may also like:
- Convert Currency on your Website or in a WordPress Post (with Shortcode)
- [Shortcode] Easily post an aviation Metar report into your post or page with shortcode
- Skype Status (Text or Image) with WordPress Shortcode
- [Shortcode] examples [3] – Text Boxes
- [Shortcode] Easily post an aviation TAF report into your WordPress post or page with shortcode


Recent Comments