Site logo

Archived topic

Remove pagination from last page of Category

5 replies · Started by Jagdish on March 7, 2019

Viewing posts 1–6 of 6

Is it possible to remove pagination from last page of Category?

Like if I have 21 posts in a category and 10 posts per page, on third page there is only one post. I do not want to show navigation under this one post.

Please help.

Hi there,

So if people navigate to the last page, they wouldn't be able to navigate back to the first and second page?

Hi,
Yes, because I am putting ads in between the posts and when odd number of posts appear on last page, there is an ad in the end before navigation buttons.

And Adsense doesn't like any clickable button near the ad unit.

Or please suggest me any other way to achieve this.

Not sure if this will work, but let's see:

add_action( 'wp', function() {
    global $wp_query;
    $current_page = $wp_query->get( 'paged' );

    if ( ! $current_page ) {
        $current_page = 1;
    }

    if ( $current_page == $wp_query->max_num_pages ) {
        add_filter( 'generate_show_post_navigation', '__return_false' );
    }
} );

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

Yes, This worked.

Thanks a ton Tom.

You're welcome :)

This archived topic is closed to new replies.