Jetpack by WordPress.com
[resolved] Change location of Related Posts (6 posts)

  1. Michael Van Den Berg
    Posted 2 years ago #

    Hello there!

    I want to move Related Posts to a different location.

    If already used the code on this page:
    To move the Sharing Icons and Likes to another location.

    Works perfectly!

    But I couldn't find how to move Related Posts to another location.
    Not on this page:
    Nor anywhere else.

    Does someone has a suggestion? Thank you!

    Best regards,


  2. lettergrade
    Posted 2 years ago #

    Hi Michael,

    It's not something currently offered, exactly, but I did find a suggestion for you in this thread.

    We haven't tested this specifically, but in JP 3.0, there is a shortcode for related posts now.

    As long as it is within the Loop, something like `do_shortcode( '[jetpack-related-posts]'); and unhooking the original filter should work in theory.

    Let us know if that helps!

  3. Michael Van Den Berg
    Posted 2 years ago #

    Hi lettergrade!

    Thank you so much for your reply!

    Just one problem: I don't have a clue on how to unhook the original filter! :P

    I've looked in the source code:

    And in the Codex:

    But I'm to much of a n00b to make sense of it....

  4. Michael Van Den Berg
    Posted 2 years ago #

    I tried something like this:

    function ap_remove_related_posts() {
        remove_filter( 'the_content', 'filter_add_target_to_dom',19 );
    add_action( 'wp', 'ap_remove_related_posts' );

    And this:

    function ap_remove_related_posts() {
        remove_filter( 'the_content', 'action_frontend_init',10 );
    add_action( 'loop_start', 'ap_remove_related_posts' );

    And several variants.

    Nothing helps. It's just a guessing game for me...

    Anyone out there who is a bit more knowledgeable about these things? :P

  5. Brandon Kraft
    Happiness Engineer
    Plugin Contributor

    Posted 2 years ago #

    You're really close.

    function remove_jprp(){
    	$jprp = Jetpack_RelatedPosts::init();
    	remove_filter( 'the_content', array( $jprp, 'filter_add_target_to_dom' ), 40 );
    add_action('wp', 'remove_jprp', 11);

    Since Related Posts is a singleton, we can call it up again and it'll return the same instance we already have. We have to call it in the remove_filter since the filter_add_target_to_dom is a function with the Jetpack_RelatedPosts class and so not generally available.

    We need to match the priority levels, so 40.

    On the add_action, we need to make sure we call it after the initial add_filter had been thrown in to the mix. Adding it directly to the wp hook at priority 11 takes cares of us.


  6. Michael Van Den Berg
    Posted 2 years ago #

    Hi Brandon,

    Better late then sorry I guess: but thank you! It worked perfectly!

    Best regards,


Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Jetpack by WordPress.com
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic