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

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:

{code type=php}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 ‘‘.$text.’‘;

}
add_shortcode(‘donate’, ‘donate_shortcode’);{/code}

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