Answer the question
In order to leave comments, you need to log in
How to hide an archive in WordPress?
Hello.
On my site, like on all WordPress sites, there are the following pages:
my-site.ru/date/2015/page/5
my-site.ru/date/2015/page/21
my-site.ru/date/2014/ page/7
my-site.ru/date/2013/page/18
How to get rid of these pages?
How can I prevent these pages from opening at all?
Or when accessing them, there was a redirect to the main one.
There is an "Archive" in the sidebar. I removed it. Appearance -> Widgets.
But these pages naturally remained.
Found wp_get_archives function. I tried to comment it out.
But it affects something global.
Answer the question
In order to leave comments, you need to log in
/* Register template redirect action callback */
add_action('template_redirect', 'meks_remove_wp_archives');
/* Remove archives */
function meks_remove_wp_archives(){
//If we are on category or tag or date or author archive
if( is_category() || is_tag() || is_date() || is_author() ) {
global $wp_query;
$wp_query->set_404(); //set to 404 not found page
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question