How do I remove unwanted pages like archive, search, etc.?

By default WordPress pushes out a whole array of pages I don’t want or need – archive, author, blog, monthly, recent posts, categories, comments, attachment, taxenomies, search, search results, and probably a few others I’ve missed.

Most of the time I’m building regular broshure websites with no need for anything except a few fairly static pages. How do I get rid of all the other pages? Is there a plugin that will do this? Do I have to set up a dozen redirects in the .htaccess? I’ve tried searching, but all I find is how to hide parts of a page, or customise the sitemap to hide from searches. But I don’t want those pages at all, so even entering the direct URL shouldn’t work.

Related posts

Leave a Reply

5 comments

  1. You could redirect anything that’s not a page or admin to home via the parse_query action:

    function wpa_parse_query( $query ){
        if( ! is_admin() && ! $query->is_page() ) {
            wp_redirect( home_url() );
            exit;
        }
    }
    add_action( 'parse_query', 'wpa_parse_query' );
    

    If it’s not an admin screen or a query for a page, it’ll redirect. You can see all of the types of pages this will remove under the Conditional Tags page in Codex.

  2. You can user another small script, without adding any plugin. There is a post here and the code to add in the index.php of your theme is this:

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

    Hope you find it useful.

  3. For anyone wondering, I ended up using .htaccess 301 redirects.

    # Redirect useless pages
    Options +FollowSymlinks
    RewriteEngine on
    RedirectMatch 301 ^/portfolio/.*$ /gallery/
    RedirectMatch 301 ^/author/.*$ /
    RedirectMatch 301 ^/category/.*$ /
    RedirectMatch 301 ^/tag/.*$ /
    RedirectMatch 301 ^/20.*$ /
    

    The blogpost archive ^/20.*$ isn’t ideal, but it will have to do for now. Also don’t know what other pages I might’ve missed.

  4. It can also be achieved using the template_redirect hook.

    You can check for each type of archives pages, or “disable” them altogether.

    • Return a 404error or redirect to another page, I prefer the 404 approach-

    In functions.php :

    /* Disable archives pages */
    add_action('template_redirect', 'my_disable_archives_function');
    
    function my_disable_archives_function()
    {
      /* Conditional checks examples:
          is_category() 
          is_tag()
          is_date()
          is_author()
          is_tax()
          is_search() ... */
    
        // Return a 404 for all archive types, except the my_custom_post_type archive.
        $post_types = array('my_custom_post_type');
    
      if ( (is_archive() && !is_post_type_archive( $post_types )) )
      {
          global $wp_query;
          $wp_query->set_404();
          status_header(404);
      }
    }