BTW here is the solutions I tried with the code commented out explaining why it did not work
<?php
// For example: https://domain.com/cpt/page/2
// Note: This is for all custom and default post types including WordPresses Blog and Pages.
// It doesn't touch single pages/posts if they happen to be set to multiple pages
// Needs to remove /cpt/page/2 pages and return a 404
// Needs to remove <link rel="next" ... tags
add_action( 'init','ess_remove_some_actions' );
function ess_disable_post_type_pagination( $query ) {
if ( is_archive() ) {
// remove_action( 'wp_head', 'adjacent_posts_rel_link_wp_head', 10, 0 ); // Doesn't Work - Functionality removed in WP 5.6
// $query->set( 'nopaging' , true ); // Doesn't work - It removes the link BUT also overrides the query and returns all results
}
}
add_action( 'pre_get_posts', 'ess_disable_post_type_pagination' );
I was able to set this through SlimSEO. You can also do it in rank math which I believe you use:
I was also able to get archive and homepage pagination page to return a 404 (even the homepage if you try domain.com/page/2).
// For example: domain.com/cpt/page/2 or domain.com/page/2
// Note: This is for the home page and all custom and default post types including WordPresses Blog and Pages.
// It doesn't touch single pages/posts if they happen to be set to multiple pages
// When using ajax and infinite scroll or load more button (so archive multi-page query stays main archive page)
// - Needs to remove /cpt/page/2 pages and return a 404
// - Needs to remove <link rel="prev" ... and <link rel="next" ... tags (use SlimSEO Settings Links switch to do this)
function ess_404_not_needed_pagination() {
// is_front_page() returns true if the user is on the page or page of posts that is set to the front page on Settings->Reading->Your homepage displays
// So if you set about us as the front page then this conditional will only be true if showing the about us page.
// is_home() return true when on the posts list page, This is usually the page that shows the latest
// if we are on an archive that is paged then 404
if (( is_home() || is_front_page() || is_archive() ) && is_paged()) {
global $wp_query;
$wp_query->set_404();
status_header(404);
}
}
// Disable access
add_action( 'template_redirect', 'ess_404_not_needed_pagination' );
A 404 status code will be used for these URLs and in most cases only the default 404 bricks page will be used (not a custom 404 template). This is a current bug in bricks.