X

How to Use PayPal Donation Shortcode in WordPress

Snippets by IsItWP

Are you looking for a way to use the PayPal donation shortcodes for donation links within your blog? While there’s probably a plugin for this, we have created a quick code snippet that allows you to use PayPal donation shortcode in WordPress.

Instructions:

All you have to do is add this code to your theme’s functions.php file or in a site-specific plugin.

This code comes with three different attributes: account, onHover, and for. The account attribute receives your paypal email address (the default is your admin email address), the onHover attribute sets the anchor title attribute that displays when you hover over the link, and the for attribute is the title of the donation (the default is your post title).

<?php
function donate_shortcode( $atts, $content = null) {
global $post;extract(shortcode_atts(array(
'account' => 'your-paypal-email-address',
'for' => $post->post_title,
'onHover' => '',
), $atts));</p>
<p>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');
?>

These are the PayPal donation shortcodes. You can change the emails in the code below:

[donate]
[donate]Donate Now[/donate]
[donate account="you@yoursite.com" onHover="Thanks" for="Title"]
[donate account="you@yoursite.com" onHover="Thanks" for="Title"]Donate Now[/donate]

Note: If this is your first time adding code snippets in WordPress, then please refer to our guide on how to properly add code snippets in WordPress, so you don’t accidentally break your site.

If you liked this code snippet, please consider checking out our other articles on the site like: 43 best WordPress photography themes and how to create a contact form in WordPress.

Comments  Leave a Reply

  1. Tweets that mention Wordpress Paypal donation shortcode – wpsnipp.com Wordpress code snippets for your blog -- Topsy.com February 4, 2011 at 5:43 pm

    […] This post was mentioned on Twitter by HN Firehose and wp_freak, WPSNIPP. WPSNIPP said: #wordpress Paypal donation shortcode http://bit.ly/e7dnmj #blog please RT 🙂 […]

  2. WordPress Paypal donation shortcode – wpsnipp.com WordPress code snippets for your blog…

    Add Paypal donation button to your posts using shortcode…

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our privacy policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

WordPress Launch Checklist

The Ultimate WordPress Launch Checklist

We've compiled all the essential checklist items for your next WordPress website launch into one handy ebook.
Yes, Send Me the Free eBook!
[60% OFF Today!]
[60% OFF Today!]
[10% OFF Today!]
[10% OFF Today!]
[50% OFF Today!]
[50% OFF Today!]