Quick Shortcode to Add a PayPal Donation Link to Any WordPress Post or Page

This is a really useful function that will allow you to use a shortcode to easily add a donation link as you’re writing a post. If you often take donations, add this to your theme’s functions.php file to make the shortcode available for use at any time:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
function donate_shortcode( $atts ) {
extract(shortcode_atts(array(
'text' => 'Make a donation',
'account' => 'REPLACE ME',
'for' => '',
), $atts));

global $post;

if (!$for) $for = str_replace(" "," ",$post->post_title);

return '<a class="donateLink" href="https://www.paypal.com/cgi-bin/webscr?cmd=_xclick&business='.$account.'&item_name=Donation for '.$for.'">'.$text.'</a>';

}
add_shortcode('donate', 'donate_shortcode');

You can replace the text with your own and also replace the account section with your PayPal email address. Now when you’re writing a page or post, you can add the shortcode:

[donate]

You’ll get a link automatically added to your post, as shown below:

Source: ThemeForest.net

Tags ,

Comments (5)

Participate