Site logo

Archived topic

Duplicate Post Navigation in CPT

13 replies · Started by Cris on November 17, 2020

Viewing posts 1–14 of 14

Hi

I use CPT configured to show the post navigation as you indicate here. It worked fine when I did it a long time ago but now, the "previous post" and "next post" links are displayed in duplicate. Any idea why this happens?

Hi there,

Good question - I think that's because we've included the post navigation in the footer entry meta.

What happens if you remove that code? Does it remove both of them?

Let me know :)

Hi Leo,

Yes! If I delete the code, both of them disappear

Can you try add this snippet as well?

add_filter( 'generate_footer_entry_meta_items ', function( $items ) {
    if ( is_singular( 'your-post-type' ) ) {
        return;
    }
	return $items;
} );

It does not work.

Edited the code above. Can you give it another shot?

Make sure to edit your-post-type

Thanks Leo but it doesn't work either.

I don't forget to edit "your-post-type" :)

Instead of the original function you linked to, do this:

add_filter( 'generate_footer_meta_post_types', function( $post_types ) {
    $post_types[] = 'your-post-type';

    return $post_types;
} );

add_filter( 'generate_footer_entry_meta_items ', function( $items ) {
    if ( is_singular( 'your-post-type' ) ) {
        return array(
            'post-navigation',
        );
    }

    return $items;
} );

Hello Tom

If I replace the original, all the previous and next links disappear.
If I add it after the original, there are no changes.

Now yes, Tom! Thanks a lot.

One last thing. For 2 or more CPTs, do I have to duplicate the function?

Nope, you can do this:

add_filter( 'generate_footer_meta_post_types', function( $post_types ) {
    $post_types[] = 'your-post-type';
    $post_types[] = 'another-post-type';
    $post_types[] = 'one-more';

    return $post_types;
} );

add_filter( 'generate_footer_entry_meta_items ', function( $items ) {
    $post_types = array( 'my-post-type', 'another-post-type', 'one-more' );

    if ( is_singular( $post_types ) ) {
        return array(
            'post-navigation',
        );
    }

    return $items;
} );

Hope this helps :)

Perfect! Many thanks to the whole team.
You do a spectacular job.

Glad we could help :)

This archived topic is closed to new replies.