Archived topic
Want to disable pagination in homepage
11 replies · Started by John on January 29, 2020
Hello
I am using tasty but in my homepage showing pagination. screenshot https://prnt.sc/quofn9
How can I disable it?
Thanks
Hi there,
We could certainly do that but how can a user get to the second page without the pagination?
Let me know :)
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
Try this CSS:
.home.blog .paging-navigation {
display: none;
}
Its just hide from front end but code is still there. Is there anyway to disable instead hide by CSS?
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/
Tried the code via code snippet plugin. https://prnt.sc/qup8gm
But unfortunately Its not work.
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.
Gone through the ref page but Its hard to understand for me because I am not familiar with too much code
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' );
tried and showing 5 posts in homepage but pagination still there.
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