Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

How would one move the sharedaddy buttons included in Jetpack to be placed before a post's or page's content, rather than after it? I see that in sharing-service.php the function that prints the buttons is hooked to the_content filter hook: add_filter( 'the_content', 'sharing_display', 19 );

I'm not sure what to place in my functions.php file to override that, though. I'm assuming I somehow need to cause the output from sharing-service.php to be prepended to the_content rather than appended to it.

share|improve this question

3 Answers 3

up vote 5 down vote accepted

Basically it line 480 in sharing-service.php where it says:

return $text.$sharing_content;

and it should be

return $sharing_content.$text;

now changing that file won't keep your changes on updates so you can copy that function (sharing_display) to your functions.php and rename it to something different say my_sharing_display and make the change there.

Next you need to remove the filters that plugin adds and replace with your own so in your functions.php add:

//remove old
remove_filter( 'the_content', 'sharing_display');
remove_filter( 'the_excerpt', 'sharing_display');
//add new
add_filter( 'the_content', 'my_sharing_display', 19 );
add_filter( 'the_excerpt', 'my_sharing_display', 19 );

Update

the remove_filter hook is not actually removing because it's missing the priority parameter , from the codex:

Important: To remove a hook, the $function_to_remove and $priority arguments must match when the hook was added. This goes for both filters and actions. No warning will be given on removal failure.

so change :

remove_filter( 'the_content', 'sharing_display');
remove_filter( 'the_excerpt', 'sharing_display');

to:

remove_filter( 'the_content', 'sharing_display',19);
remove_filter( 'the_excerpt', 'sharing_display',19);
share|improve this answer
    
Thanks for the tip. That partially worked - the sharing buttons still appear at the bottom of posts (as well as at the top, now). I'm not sure why that remove_filter isn't working, but it isn't. Any thoughts? –  tnorthcutt Mar 23 '11 at 14:29
    
@tnorthcutt: yep, i updated the answer –  Bainternet Mar 23 '11 at 14:36
    
You can check the return value of remove_filter or remove_action, if it is true the hook was found and removed, otherwise it will be false. So you won't get a warning, but you can check the result if it doesn't do what you expected. –  Jan Fabry Mar 24 '11 at 18:10

try this:

<?php 
if ( function_exists( 'sharing_display' ) ) {
    echo sharing_display();
}
the_content();
?>

worked for me

share|improve this answer

Another option, would be to edit the Jetpack plugin files directly. Take out both add_filters() for the_content and the_excerpt from sharing-service.php.

Then you can manually put <?php echo sharing_display(); ?> in your theme's loop wherever you want the sharing bar to be located.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.