Moving JetPacks Related Posts to a new position in Genesis

JetPack has a great Related Posts module, here’s how to move it further down the page below posts meta info or anywhere else you like by using a shortcode provided by JetPack.

In Genesis Themes for instance, it positions itself in the genesis_entry_content hook at the bottom. Lets say you wanted this below the post meta category information.

jetpack-related-posts-genesis-hook

 

Well, JetPack has a shortcode that you can use to position the related posts where ever you like.

<?php // <~ Remove the opening PHP tag
// Ref - https://jetpack.com/support/related-posts/customize-related-posts/#delete
// Remove JetPack Related Posts
function jetpackme_remove_rp() {
if ( class_exists( 'Jetpack_RelatedPosts' ) ) {
$jprp = Jetpack_RelatedPosts::init();
$callback = array( $jprp, 'filter_add_target_to_dom' );
remove_filter( 'the_content', $callback, 40 );
}
}
add_filter( 'wp', 'jetpackme_remove_rp', 20 );
//reposition JetPack Related Posts Somewhere else
function wpb_jp_posts() {
echo do_shortcode(' [jetpack-related-posts] ');
}
add_action( 'genesis_entry_footer', 'wpb_jp_posts', 15 ); //use required hook for position
view raw jetpack.php hosted with ❤ by GitHub

So when the above snippet is added to functions.php the default position is removed in the first function and in the second function the JetPack shortcode is used to reposition it using the genesis_entry_footerhook at a lower priority.

 

move-jetpack-related-posts

For a non-Genesis theme you would just add the shortcode to your PHP template files where you want the related posts to appear at a different position.

<?php echo do_shortcode([jetpack-related-posts]); ?>

Further reference here.

4 Comments

  1. di sekitar on December 17, 2016 at 2:01 am

    wow this really work, thanks

    now my share button go above my related post.

  2. Thea on June 7, 2016 at 11:10 pm

    Hi Guys
    I was hoping to ask a quick question re this code please. Sorry probably a silly question but I’m not great at this code stuff. When we copy the code do we take out the bits in grey like remove the opening php tag and remove jetpack related posts and reposition jetpack related posts somewhere else and the use required hook for position. At first this last one was the only one I thought I had to take out but after having a closer look I am not so sure. Perhaps we simply copy from the word function. Come to think of it, when you say add to functions.php does that mean just your normal php file or something else?
    Thanks in advance and again sorry for the stupid question!
    Thanks
    Thea

    • Neil Gowran on June 10, 2016 at 4:46 am

      Hi Thea,

      You can leave in the bits in grey as they are comments and have 2 backslashes before them which says to PHP to ignore them but yes remove the opening PHP tag and the functions.php file is the one inside your theme.

  3. Bappi on April 22, 2016 at 3:03 am

    Thank you, Dear from the core of my Heart….
    many thanks .
    good bless you..

Leave a Comment





%d bloggers like this: