Shortcodes

Add Paypal Donate WordPress Shortcode

Paypal

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]
Back to top

Learn how to code with Treehouse

  • Learn projects with access to 1000+ videos
  • Practice live with our Code Challenge Engine
  • Get help in our members-only forums

Start with a 7 day free trial