RBA Cash Rate: 4.35% · 1AUD = 0.67 USD · Inflation: 4.1%  
Leading Digital Marketing Experts | 1300 235 433 | Aggregation Enquires Welcome | Book Appointment
Example Interest Rates: Home Loan Variable: 5.20% (5.24%*) • Home Loan Fixed: 5.48% (6.24%*) • Fixed: 5.48% (6.24%*) • Variable: 5.20% (5.24%*) • Investment IO: 5.78% (6.81%*) • Investment PI: 5.49% (6.32%*)

Include a PayPal Donate Link in WordPress With Shortcode

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; there are far more effective and less intrusive ways of supporting your website 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.

The following shortcode may be used on a WordPress website to render a text donation link or image that will redirect to PayPal.

The Result

The shortcode of [donate image="1"] returns an image as follows. Click on it to see the result (just don't donate anything!).

A text link, using [donate image="0"] returns the following:

Make a donation with PayPal

WordPress Shortcode

Copy and paste the WordPress function into your theme's functions.php file or, if you sensibly have one installed, your custom functions plugin.

1
<?php 
2
/*
3
 Include a PayPal Donate Link in WordPress With Shortcode
4
 http://www.beliefmedia.com/code/paypal-link-wordpress
5
*/
6
 
7
function beliefmedia_paypal_donate($atts) {
8
 
9
  extract(shortcode_atts(array(
10
    'text' => 'Make a donation with PayPal',
11
    'account' => 'you@youremail.com', // Your PayPal email
12
    'image' => 0,
13
    'image_url' => 'http://www.beliefmedia.com/wp-images/misc/paypal_donate.png',
14
    'itemname' => 0, // replace
15
    'itemnumber' => 0, // replace
16
    'amount' => '5', // default donation
17
  ), $atts));
18
 
19
   global $post;
20
   global $authordata;
21
 
22
   $blog_name = get_bloginfo('name');
23
   $via = str_replace(' ', '+', $post->post_title);
24
   if (!$itemname) $itemname = str_replace(' ', '+', $blog_name);
25
   if (!$itemnumber) $itemnumber = str_replace(' ', '+', $authordata->display_name);
26
 
27
   /* Image or link? */
28
   $anchor = (!$image) ? '' . $text . '' : '
29
<p align="center"><img src="' . $image_url . '">';
30
 
31
  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 . '&currency_code=USD">' . $anchor . '</a>';
32
}
33
add_shortcode('donate', 'beliefmedia_paypal_donate');

If you require shortcode to work in a sidebar widget, you'll have to enable the functionality with a filter. If you're using our custom functions plugin, you'll have that feature enabled by default.

Shortcode Attributes

text

Text that will link to PayPal. Defaults to "Make a donation with PayPal".

image & image_url

To render an image link use image="1", and to return a text link use image="0". If an image is returned, ensure you provide a full URL to the image location.

account

Email attached to your PayPal account.

itemname& itemnumber

The 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

The default amount to be paid. Will prompt for a value if not defined. Not required.

Considerations

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 (say, for different authors), then shortcode is almost certainly the better option.

Download our 650-page guide on Finance Marketing. We'll show you exactly how we generate Billions in volume for our clients.

  E. Australia Standard Time [ UTC+10, Default ] [ CHECK TO CHANGE ]

  Want to have a chat?
 

Like this article?

Share on Facebook
Share on Twitter
Share on Linkdin
Share on Pinterest

Leave a comment