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
sharing. Bookmark the
permalink.
Explore the benefits of Jetpack
Learn how Jetpack can help you protect, speed up, and grow your WordPress site.
Compare plans
Like this:
Like Loading...
Related