[Support request] Want to disable pagination in homepage

Home Forums Support [Support request] Want to disable pagination in homepage

Home Forums Support Want to disable pagination in homepage

Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #1148460
    John

    Hello

    I am using tasty but in my homepage showing pagination. screenshot https://prnt.sc/quofn9

    How can I disable it?

    Thanks

    #1148466
    Leo
    Staff
    Customer Support

    Hi there,

    We could certainly do that but how can a user get to the second page without the pagination?

    Let me know 🙂

    #1148478
    John

    Google can treat as duplicate content second or later archive page.

    Pagination is important for category page but in homepage I don’t want it.

    Showing 5 post in homepage is enough for me.

    Note – I only want to disable pagination from homepage not category page

    #1148481
    Leo
    Staff
    Customer Support

    Try this CSS:

    .home.blog .paging-navigation {
        display: none;
    }
    #1148485
    John

    Its just hide from front end but code is still there. Is there anyway to disable instead hide by CSS?

    #1148500
    Leo
    Staff
    Customer Support

    We can try using this snippet to set the home page post number to 5:

    add_action( 'pre_get_posts', function( $query ) {
        if ( is_front_page() && is_home() ) {
            $query->set( 'posts_per_page', 5 );
        }
    } );

    Adding PHP: https://docs.generatepress.com/article/adding-php/

    This is controlled by WordPress itself so more info here:
    https://developer.wordpress.org/reference/functions/query_posts/

    #1148508
    John

    Tried the code via code snippet plugin. https://prnt.sc/qup8gm

    But unfortunately Its not work.

    #1148514
    Leo
    Staff
    Customer Support

    What about the example here?
    https://developer.wordpress.org/reference/functions/query_posts/

    The snippet below “For example, on the homepage, you would normally see the latest 10 posts. If you want to show only 5 posts (and don’t care about pagination),” seems to be what you are after.

    #1148521
    John

    Gone through the ref page but Its hard to understand for me because I am not familiar with too much code

    #1148528
    Leo
    Staff
    Customer Support

    Try this code:

    function wpdocs_five_posts_on_homepage( $query ) {
        if ( $query->is_home() && $query->is_main_query() ) {
            $query->set( 'posts_per_page', 5 );
        }
    }
    add_action( 'pre_get_posts', 'wpdocs_five_posts_on_homepage' );
    #1148538
    John

    tried and showing 5 posts in homepage but pagination still there.

    #1148553
    Leo
    Staff
    Customer Support

    Ahh right.

    Unfortunately we don’t have a filter for that as it’s not really logical to remove the pagination under normal circumstances.

    You would need to create a child theme, copy post-meta.php in to the child theme folder and remove is_home() || from this line:
    https://github.com/tomusborne/generatepress/blob/7f9a2662f3388295407e96065fafe348b28a01b6/inc/structure/post-meta.php#L74

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