WordPress: Paypal donation button using shortcodes
Do you want to add a PayPal donation button so that your readers can send you a few dollars and say thank you? It can be very simple to integrate a PayPal donate button in your posts or WordPress website.
Just copy-paste the code below in functions.php. Replace the email address with your PayPal email address. Make sure to take care of the PHP start and end tags.
<?php function donate_shortcode( $atts, $content = null) { global $post;extract(shortcode_atts(array( 'account' => get_bloginfo('admin_email'), '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'); // Make shortcodes work in widgets add_filter('widget_text', 'do_shortcode'); ?>
Now whenever you want to add a donate button, just use one of the following shortcodes. You can customize your email as well as donate button text.
[donate] [donate]Donate Now[/donate] [donate account="[email protected]" onHover="Thank You" for="Title"] [donate account="[email protected]" onHover="Thank You" for="Title"]Donate Now[/donate]
The $account variable defines your PayPal email address (default is the email address associated with the admin of the WordPress site), the $onHover variable sets the anchor title attribute as you hover over the link and the $for attribute is the description of the donation (default is your post title).