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:

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');

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:

FREE EBOOK
Your step-by-step roadmap to a profitable web dev business. From landing more clients to scaling like crazy.

By downloading this ebook I consent to occasionally receive emails from WPMU DEV.
We keep your email 100% private and do not spam.

FREE EBOOK
Plan, build, and launch your next WP site without a hitch. Our checklist makes the process easy and repeatable.

By downloading this ebook I consent to occasionally receive emails from WPMU DEV.
We keep your email 100% private and do not spam.

[donate]

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

Source: ThemeForest.net

Tags: