Sharing Buttons Function

The ngfb_get_sharing_buttons() function can include sharing buttons anywhere within your functions and template files. As an example, the following PHP code includes the Facebook, Google+, and Twitter sharing buttons from within a loop, post, or page (the $post->ID must be available):

The sharing button names for the array can be:

  • buffer
  • facebook
  • gplus
  • linkedin
  • managewp
  • pinterest
  • reddit
  • stumbleupon
  • tumblr
  • twitter

You can also use the ngfb_get_sharing_buttons() function outside of a loop, post, or page, but you will have to provide additional information to the function. Since the $post variable is not available outside of a loop (to get the permalink URL), at a minimum you will have to provide the webpage URL. Here’s an example from a custom NextGEN Gallery template (plugins/nextgen-gallery/view/):

This creates a Pinterest and Tumblr button to share a picture from a NextGEN Gallery, sets the URL to the current webpage address, and uses the picture’s caption as well.

2 thoughts on “Sharing Buttons Function

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>