[WordPress] How to return status 404 on the second and subsequent pages when the top page is a fixed page

[WordPress] How to not create author/poster archives

naouniverse.com is built on WordPress.
The top page (https://naouniverse.com) uses home.php, and the top page of the blog (https://naouniverse.com/blog) is coded with conditional branching within page.php.

Yes, the top page is a fixed page.

There is one thing that I noticed recently.
As the number of blog articles increases, there is a serious problem that the second and subsequent pages exist in home.php.

2nd page and beyond exist

You can access it at https://naouniverse.com/page/2...

This is not a problem for regular WordPress blogs (I think), but if you want to display a completely fixed top page like this site, page duplication will occur, which is not a good thing from an SEO perspective. )is.

I decided to deal with the problem as follows.

Returns status 404 from second page onwards

Yes, as you read, the status 404 is returned from the second page onwards.

Added the following description to functions.php.

<?php add_action( 'template_redirect', 'status404' ); function status404() { if (is_home() && is_paged()){ global $wp_query; $wp_query-> set_404(); status_header(404); } } ?>

Home.php and from the second page onwards, a status 404 is returned.

When I preview it...↓It will return a status 404.

It seems to be working well.
good···

Afterword

When I first noticed this problem, I tried various things such as writing in the Apache configuration file .htaccess (dot Htaccess), but it didn't work.

It seems safe to write it in functions.php above.

  • Add this entry to Hatena Bookmarks

At "naouniverse.com", the administrator writes about things, things, and the world that interest him.
Gadgets, cameras, design, programming, L'Arc~en~Ciel, etc...