Remove archive pages in WordPress, how to

I think that in most blogs (that is not all) archive pages are redundant content and there’s no need to…

Settembre 8, 2015

I think that in most blogs (that is not all) archive pages are redundant content and there’s no need to make these pages available. So I’ve found a method to remove archive pages from WordPress without any plugin but with just a few lines of PHP code.

To remove archive pages in WordPress to prevent users accessing urls like http://www.yourdomain.com/2015/ I’ve found this way that doesn’t affect urls of categories and permalink structure. Remove your archive.php from your theme, so archives are handled by the index.php of your theme (rename it __OLD__archive.php if you’re not sure).

Then open the index.php file of your theme and put these lines at the beginning. This will force WordPress to send 404 page to any request of archives.

Remove archive pages with php

The code snippet:

if(is_archive()) {
	// force 404
	$wp_query->set_404();
	status_header( 404 );
	nocache_headers();
	include("404.php");
	die;
}

As you can see you don’t need any plugin to remove archive pages from WordPress, because you can achieve the result with only a few lines of php in your index.php file. These lines modify the headers and force WordPress archive requests to behave like a 404 (Not found) page.

Archive pages are WordPress pages that show a list of posts (custom or not) organized by date, you can browse them yearly or monthly simply adding /year/month to any wordpress site. You can try this: /2015/ year archive for this site.

You can read more about WordPress archive pages on Codex article “Creating an Archive Index“, but if you need you can remove archive pages, since these pages are not necessary for most blogs, it’s a redundant page that shows artices already lined by category pages and tag pages.

Remove archive pages for SEO purposes

Finally, I also think that removing archive pages can improve your SEO, because in Sarch Engine Optimization you need to put relevant content into the serp and you have not to duplicate contents. Archive pages are very similar to category and tag pages, so – if you push the Google spider to index hundreds or even thousands of pages which only contain links to your posts already linked with better keywords (tags and categories) – you are working for your competitors and not for you.

Author

PHP expert. Wordpress plugin and theme developer. Father, Maker, Arduino and ESP8266 enthusiast.

Recommended

How to add rel=”nofollow” to links with preg_replace()

Adding rel="nofollow" to external link is a good SEO practice.

Settembre 22, 2015

Social buttons: the fastest way for WordPress, without plugins

NOTE: the code in this post is written for WordPress but you can easily translate it in any language. You’re here…

Settembre 15, 2015

Optimize WordPress, a long list of tips

In the above image you can see your WordPress before reading this post, and after the optimizations you will make…

Limit the number of categories for posts in WordPress

CHOOSE ONLY ONE CATEGORY WORDPRESS If you need to limit the number of categories used by the authors of your…

Settembre 14, 2015

WordPress anyone can register, but no email confirmation

Many times it has happened to me that my WordPress installation properly send emails using wp_mail directly, specifing also the…

Agosto 25, 2015

WordPress 4.1.1 is available! Please update now.

Sometimes you find messages like “WordPress 4.1.1 is available! Please update now.“, in italian it is: “È disponibile WordPress 4.1.1! Aggiorna…

Marzo 16, 2015