Skip to content

Instantly share code, notes, and snippets.

@eri-trabiccolo
Created February 10, 2015 17:25
Show Gist options
  • Select an option

  • Save eri-trabiccolo/6d71aa9f5a4995503700 to your computer and use it in GitHub Desktop.

Select an option

Save eri-trabiccolo/6d71aa9f5a4995503700 to your computer and use it in GitHub Desktop.
Add paypal donate button in the menu
function get_ppdonate_form( $echo = true ){
ob_start();
// replace value="XXXX" with your button id
?>
<form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_top">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="XXXX">
<input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_donate_LG.gif" border="0" name="submit" alt="PayPal – The safer, easier way to pay online!">
</form>
<?php
$form = ob_get_contents();
if ( $form ) ob_end_clean();
if ( $echo )
echo $form;
else
return $form;
}
add_filter('wp_nav_menu_items', 'add_ppdonate_form_to_menu', 10, 2);
function add_ppdonate_form_to_menu($items, $args) {
// If this isn't the main navbar menu, do nothing
if( !($args->theme_location == 'main') )
return $items;
// On main menu: put class around the form and append it to the menu items
return $items . '<li class="my-nav-ppdonate">' . get_ppdonate_form( false ) . '</li>';
}
@sanjeevthakur58
Copy link

Thanks code working for me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment