How to insert another plugin before the Jetpack sharing buttons

Explore the benefits of Jetpack

Learn how Jetpack can help you protect, speed up, and grow your WordPress site. Get up to 50% off your first year.

Explore plans

Jetpack sharing buttons are added immediately after the post content. In some cases, you may want to insert a new element between your post content and the sharing buttons.

To control whether that element will appear before or after the Jetpack sharing buttons, you will have to change the priority of the filter. In the example below, we’ve added an author box and used the priority 18. As long as the priority is less than 19, it will appear before the sharing buttons.


<?php
/**
* When hooked to either the_content or the_excerpt filters,
* this should append the contents of the `author-box.php`
* file in your theme before the Jetpack ShareDaddy contents
* is added, so long as the priority is 18 or less!
* (as ShareDaddy's sharing options go in at priority 19)
*
* @param string $content The post content as passed to the function
* @returns string The content with the author box appended to it.
*/
function my_author_box( $content = '' ) {
ob_start();
get_template_part( 'author', 'box' );
$author_box = ob_get_clean();
return $content . $author_box;
}
add_filter( 'the_content', 'my_author_box', 18 );

This entry was posted in Code snippets, Tips & Tricks and tagged . Bookmark the permalink.

Jeremy Herve profile
Jeremy Herve

Jetpack Mechanic 🚀 at Automattic. WordPress, board games, TV Series, music.

Explore the benefits of Jetpack

Learn how Jetpack can help you protect, speed up, and grow your WordPress site. Get up to 50% off your first year.

Explore plans

Have a question?

Comments are closed for this article, but we're still here to help! Visit the support forum and we'll be happy to answer any questions.

View support forum
  • Enter your email address to follow this blog and receive news and updates from Jetpack!

    Join 112.8K other subscribers
  • Browse by Topic