0

The backstory is I noticed the homepage was generating infinite paginated pages. This is a custom built theme.

I was using index.php and WP_Query to create 2 small 5 post loops. I figured WP_Query was pulling all of the qualifying posts and then limiting to the most recent 5, so I switched to get_posts with a foreach loop, since my understanding is that doesn't fetch all the posts, only the ones you ask for (and therefore no need for pagination). This didn't solve the issue.

Then I realized that the Settings > Readings were set to show Latest Posts, which explained why Yoast was auto-adding a "next" schema with a link to page/2/ though it shouldn't exist. By changing that to a static page and moving index.php to front-page.php, that killed off the "next" schema.

However, you can still manually go to /page/2/ on to /page/24893/ and so forth, and it still loads the same posts as page one instead of giving off a 404 error.

The problem here is that with the "next" schema having been there, Google could be indexing all that bloat infinitely. It's not, but it's a potential. The real problem is it's driving me nuts and I don't want this to be the case that those pages exist. Since they were previously exposed I'd like them to 404 now.

Every Wordpress site I've checked that I can think of that has a static homepage has the problem.

Does anybody know what's triggering this? I'm doing small static loops with get_posts and have no pagination setup and it's set to a static front-page.php.

Thanks

0

To remove relational links from the single post <head> use

remove_action( 'wp_head', 'adjacent_posts_rel_link_wp_head' );

adjacent_posts_rel_link_wp_head documentation.

To return Status 404 on paginated pages use .htaccess rule similar to following:

RewriteRule ^page/([0-9]+)/$ http://yourdomain.tld/404/ [R=404,NC,L]

.htaccess rule is not tested, but it gives you an idea.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.