A
A
AlexVoronin2016-01-05 12:16:52
WordPress
AlexVoronin, 2016-01-05 12:16:52

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

1 answer(s)
V
Vincent1, 2016-01-05
@AlexVoronin

/* 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
  }
}

Or there is another plugin https://wordpress.org/plugins/smart-archive-page-r...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question