In our WordPress blogs, the Sharing and Like buttons in Jetpack get printed at the end of the the_content() Loop function, which causes them to display at the end of our post’s text by default. But that may not be where we want them in our site’s design.
With help of these two steps you can move the Sharing buttons and Like buttons to your desired location.
1. Add the following code snippet in your functions.php file:
1 2 3 4 5 6 7 8 9 | function ft_jetpack_remove_share() { remove_filter( 'the_content', 'sharing_display',19 ); remove_filter( 'the_excerpt', 'sharing_display',19 ); if ( class_exists( 'Jetpack_Likes' ) ) { remove_filter( 'the_content', array( Jetpack_Likes::init(), 'post_likes' ), 30, 1 ); } } add_action( 'loop_start', 'ft_jetpack_remove_share' ); |
2. Find the file for the location where you’d like the sharing icons to appear and insert the following code in the area you want the Sharing or Likes buttons to appear:
1 2 3 4 5 6 7 8 9 10 | // To display sharing if ( function_exists( 'sharing_display' ) ) { sharing_display( '', true ); } // To display likes if ( class_exists( 'Jetpack_Likes' ) ) { $custom_likes = new Jetpack_Likes; echo $custom_likes->post_likes( '' ); } |
Note that you do not need to display these together; you can put sharing_display() in a separate place from the Likes display codeblock. For example you can put Sharing buttons before starting of text and Like button in a sidebar.
Now all is done. Check if the Sharing and Like buttons in Jetpack all placed at desired location in your page/post.