Paulund
2011-12-07 #wordpress

Add Paypal Donate Wordpress Shortcode

In a previous post we had a snippet on how you can make money on your Wordpress blog by placing Google Adsense on your website. This snippet was a shortcode so you can add the Google Adsense anywhere in your content. In this article there will be another Wordpress shortcode on making money by using the Paypal donate functionality. This is when you have a button on your website where people can donate money to you which goes directy into your paypal account. All you have to do is copy the following in your functions.php file and you can use the shortcode in your content.

function paypal_donate( $atts ) {  
    extract(shortcode_atts(array(  
        'text' => 'Make a donation',  
        'account' => 'Add your account name here',  
        'for' => '',  
    ), $atts));  
  
    global $post;  
  
    if (!$for) $for = str_replace(" ","+",$post->post_title);  
  
    return '<a class="paypal_donate" href="https://www.paypal.com/cgi-bin/webscr?cmd=_xclick&business='.$account.'&item_name=Donation+for+'.$for.'">'.$text.'</a>';  
  
}  
add_shortcode('donate', 'paypal_donate');

Now in your content you can use the shortcode

[donate]