We’ve made it super simple for developers and non-developers to add Social Warfare sharing buttons anywhere in your posts, pages and WordPress themes. There are two ways you can do this:
- Shortcode – for use in pages and posts
- PHP function – for use in theme files
This article will walk through each use case so you can take full advantage to Social Warfare’s placement versatility.
Using the Shortcode
You can add the share buttons inside of a post or page by using the
[social_warfare] shortcode. Wherever you place it the buttons will be generated on that page. It’s that easy.
Control Which Page is Shared
But what if you wanted to add share buttons to a page that actually share out another page? For example, what if you wanted to place share buttons on a “Thank you” page after someone signs up for your email list and you want them to share your sign-up page?
We’ve built this ability in as well! All you’ll need is the post ID for the page you want to share. You can find this by going to you Posts/Pages list and hovering your mouse over top of the titles. When you do this, a URL will appear in the bottom-left corner of your browser. Inside that URL will be a string that looks like this:
The number that immediately follows the post= is your post ID. Once you have the ID of the post/page you want people to share, simply add it into the shortcode on the “Thank you” page like this:
Just replace X with the post ID and you’re all set!
Control Which Buttons Show
With version 2.0, we’ve also added the ability to control which buttons are populated by the shortcode if you want them to be different than the site-wide settings. You can simply add the
buttons="x" parameter and insert any of the following button labels:
- Google Plus
- Stumble Upon
- Whats App
- Hacker News
So if you wanted to show the Facebook, Twitter and Pinterest buttons plus the total share count, your shortcode would look like this:
Using the PHP Function
Before manually adding Social Warfare to your theme, be sure to change the Display Location for that area of your site to “None/Manual Placement”. It does not display well when the automatically added version of the plugin and the manually added version exist on the same page.
Once that setting has been changed, you can manually add the plugin by simply adding the
social_warfare() function wherever you want it to display within your theme.
Important Note #1: It is highly recommended that any use of a function that relies on a plugin be used in a “pluggable” manner. That is to say, you should first check that the function exists prior to calling the function itself. This way if the plugin is deactivated or uninstalled, no errors will be presented from trying to call a function that is not defined.
Here’s an easy way to use our function in a safe, pluggable manner:
if(function_exists('social_warfare')): social_warfare(); endif;
Important Note #2: The team at Social Warfare highly recommend that any changes made to your theme be added in the form of a Child Theme. This will allow you to preserve your edits after updating the parent theme.