Adding PayPal Donate Button in WordPress Post and Page are very common now a days. If you think that your website containing very useful information, and for that your website viewer will love to donate and helps you out financially. Then you just need to prepare a Paypal account and have to past the below code in function.php of your WordPress site.

Easy Steps to add Donate Button in WordPress site

1. Create your PayPal account if it is not already created
2. Locate function.php in your current activated theme
3. Past the below code in function.php

function donate_shortcode( $atts ) {
    extract(shortcode_atts(array(
        'text' => 'Make a donation',
        'account' => 'YOUR PAYPAL USER NAME WILL GOES HERE',
        'for' => 'MESSAGE TO BE DISPLAIED ON DONATION PAGE',
    ), $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');

4. Just don’t forget to update 3 variables in the above code as per your requirement –
‘text’ => ‘Make a donation’,
‘account’ => ‘YOUR PAYPAL USER NAME WILL GOES HERE’,
‘for’ => ‘MESSAGE TO BE DISPLAIED ON DONATION PAGE’,

And at the last if needed you can display donate image graphics using <img> tag instead of normal text by replacing $text in –

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

5. At the very end you just have to add a short code [donate] on the WordPress page to display display button/text on it.

Here you are done, It’s time to check code the implementation.

Related posts: