Top

Daily Tip: Quick Shortcode to Add a PayPal Donation Link to Any WordPress Post or Page

September 10, 2010

This is a really useful function that will allow you to use a shortcode to easily add a donation link as you’re writing a post. If you often take donations, add this to your theme’s functions.php file to make the shortcode available for use at any time:

function donate_shortcode( $atts ) {
extract(shortcode_atts(array(
'text' => 'Make a donation',
'account' => 'REPLACE ME',
'for' => '',
), $atts));

global $post;

if (!$for) $for = str_replace(" "," ",$post->post_title);

return '<a class="donateLink" href="https://www.paypal.com/cgi-bin/webscr?cmd=_xclick&amp;business='.$account.'&amp;item_name=Donation for '.$for.'">'.$text.'</a>';

}
add_shortcode('donate', 'donate_shortcode');

You can replace the text with your own and also replace the account section with your PayPal email address. Now when you’re writing a page or post, you can add the shortcode:

[donate]

You’ll get a link automatically added to your post, as shown below:

Source: ThemeForest.net

Comments

Got something to say?

Bottom
Article Archive  |  This site is a historical archive of pressography.com, a WordPress plugin and theme blog that published between 2006 and 2012. It is preserved for reference and is not operated by, affiliated with, or endorsed by its original authors. Nothing here is for sale and no form on this site is active. If you are the original owner and would like this domain returned, please get in touch.