[Resolved] Duplicate Post Navigation in CPT

Home Forums Support [Resolved] Duplicate Post Navigation in CPT

Home Forums Support Duplicate Post Navigation in CPT

Viewing 14 posts - 1 through 14 (of 14 total)
  • Author
    Posts
  • #1535068
    Cris

    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?

    #1535199
    Leo
    Staff
    Customer Support

    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 πŸ™‚

    #1535230
    Cris

    Hi Leo,

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

    #1535338
    Leo
    Staff
    Customer Support

    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;
    } );
    #1535642
    Cris

    It does not work.

    #1536491
    Leo
    Staff
    Customer Support

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

    Make sure to edit your-post-type

    #1536700
    Cris

    Thanks Leo but it doesn’t work either.

    I don’t forget to edit “your-post-type” πŸ™‚

    #1536763
    Tom
    Lead Developer
    Lead Developer

    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;
    } );
    #1537135
    Cris

    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.

    #1537932
    Tom
    Lead Developer
    Lead Developer
    #1537971
    Cris

    Now yes, Tom! Thanks a lot.

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

    #1538357
    Tom
    Lead Developer
    Lead Developer

    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 πŸ™‚

    #1538511
    Cris

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

    #1539192
    Tom
    Lead Developer
    Lead Developer

    Glad we could help πŸ™‚

Viewing 14 posts - 1 through 14 (of 14 total)
  • You must be logged in to reply to this topic.