Simplify the process of receiving donations on your WordPress website with this user-friendly PayPal donation shortcode. This shortcode will make it easy to add a donation link to your website and make it easier to collect support from your audience.
Add this snippet of code to your themes functions.php file:
function donate_shortcode( $atts, $content = null) {
global $post;extract(shortcode_atts(array(
'account' => 'your-paypal-email-address',
'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');
Customize the Shortcode
You can change the default “Make A Donation” text to something more fitting for your site, such as “Support Us” or “Donate Now.” You can also customize the ‘item_name’ attribute to provide more context about the donation.
Adding CSS classes or inline styles to the anchor tag will help to match your site’s design. This allows you to control the link’s appearance, including colors, fonts, and hover effects.
If you have a specific PayPal donation URL, you can replace the hardcoded URL with your custom URL.
You can also expand the shortcode to accept more attributes, such as ‘currency’ or ‘amount’, allowing you to set different currency options or predefined donation amounts.
Do you need help optimizing your website to ensure your audience can find and donate to you easily? Contact our SEO Consulting experts today.