How to insert another plugin before the Jetpack sharing buttons

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 );

view raw
inc-author-box.php
hosted with ❤ by GitHub

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

Explore the benefits of Jetpack plans

Compare plans in detail to see how Jetpack can help you design, market, and secure your WordPress site.

Compare plans

Have a question about this article?

Comments are currently closed for this article, but rest assured we're still here to help! Send us a message and we'll get back to you.

Contact us
  • Enter your email address to follow this blog and receive news and updates from Jetpack!

    Join 175,060 other followers

  • Browse by topic

  • %d bloggers like this: