If it helps, at the moment I am able to do what I want using this methodology. I’m not sure if it’s the best way and I have not tested it outside my development environment. It seems to work so far. I’m hoping this inspires some feedback and possibly other solutions.
The basic idea is this:
1) Disable the built in calls to ShareThis that insert the buttons automatically on pages and posts (they do this with a call to add_filter('the_content', 'st_add_widget');
around line 285 in the sharethis.php
file in the plugin).
2) create my own action that can be called to insert the ShareThis widget where I want in my template.
3) Do all this in functions.php
so I don’t have to hack the plug-in or WordPress core. Doing it this way should allow WP and plug-in updates to run without any future issues.
Solution
Added this to my functions.php
//remove share this from all content
function remove_sharethis() {
remove_filter('the_content', 'st_add_widget');
remove_filter('the_excerpt', 'st_add_widget');
remove_action('wp_head', 'st_widget_head');
}
add_action( 'template_redirect', 'remove_sharethis' );
function print_sharethis_widget( ){
print st_widget_head();
print st_add_widget('');
}
add_action( 'custom_sharethis_widget','print_sharethis_widget');
Then in my templates I call the custom_sharethis_widget
action where I want the ShareThis buttons to appear. like this:
<div id="my-sharethis"><?php do_action( 'custom_sharethis_widget' ); ?></div>
It took me a while to work this out, so hopefully this helps someone else out.