WordPress.org

Forums

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

  1. Michael Van Den Berg
    Member
    Posted 10 months ago #

    Hello there!

    I want to move Related Posts to a different location.

    If already used the code on this page:
    http://jetpack.me/2013/06/10/moving-sharing-icons/
    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:
    http://jetpack.me/support/customize-related-posts/
    Nor anywhere else.

    Does someone has a suggestion? Thank you!

    Best regards,
    Michael

    https://wordpress.org/plugins/jetpack/

  2. lettergrade
    Member
    Plugin Author

    Posted 10 months 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
    Member
    Posted 10 months 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:
    https://github.com/Automattic/jetpack/blob/master/modules/related-posts/jetpack-related-posts.php

    And in the Codex:
    http://codex.wordpress.org/Function_Reference/remove_filter

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

  4. Michael Van Den Berg
    Member
    Posted 10 months 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 Author

    Posted 10 months 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.

    Cheers!

  6. Michael Van Den Berg
    Member
    Posted 10 months ago #

    Hi Brandon,

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

    Best regards,

    Michael

Reply

You must log in to post.

About this Plugin

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

About this Topic