Sometime you need to add the PayPal donation button in your WordPress website to allow your website visitors to donate some amount to you by using the PayPal Payment gateway.
In this tutorial, I will share some piece of code which will allow you to create a shortcode for PayPal donation button in your WordPress sites.
1 2 3 4 5 6 7 8 9 10 11 |
function donate_shortcode( $atts, $content = null) { global $post;extract(shortcode_atts(array( 'account' => 'your-paypal-email-address', 'for' => $post->post_title, 'onHover' => '', ), $atts)); if(empty($content)) $content='Make A Donation'; return '<a href="https://www.paypal.com/cgi-bin/webscr?cmd=_xclick&business='.$account. '&item_name=Donation for '.$for.'" title="'.$onHover.'">'.$content.'</a>'; } add_shortcode('donate', 'donate_shortcode'); |
Then, you use this [donate]My Text Here[/donate]
shortcode in your posts or pages. You can also use it in your template file by using below code:
1 2 3 |
<?php echo do_shortcode('[donate]My Text Here[/donate]'); ?> |
If you like FreeWebMentor and you would like to contribute, you can write an article and mail your article to [email protected] Your article will appear on the FreeWebMentor main page and help other developers.
Article Tags: add PayPal donation button, PayPal donation button, wordpress tutorial, wordpress tutorial for beginner, wordpress tutorial for beginners