404 Error On Category and Tags Pages

Okay So I'm facing a weird problem as i'm receiving 404 errors on blog category and tag pages. I'm using custom theme which includes:

  • tag.php
  • category.php
  • archive.php
  • home.php
  • index.php and
  • 404.php.

The Blog archive is working fine but when i try to load tag pages or category pages i'm being redirected to 404.php template file.

Also there is one other weird problem which i'm facing if i remove 404.php file from my theme folder the category and tag links are working fine and loads content from archive.php but it shows page not found on page title and error404 class is added inside the body tag of that page.

Here is the list of items that i've tried so far to solve the issue:

  1. Refreshed Permalink Structure.
  2. Applied Category and Tag Base.
  3. Changing the theme to twentyseventeen in which everything was fine
  4. All the code in my header and footer.php file follows wordpress theme guidelines.

Please suggest me a solution that might help to solve this as it works fine without 404.php. The Blogs and Categories on website are imported from other website using Wordpress importer.

Question Update: Why Does Wordpress redirects to 404.php even tough files category.php, archive.php and index.php are present inside Wordpress theme folder on category or tag pages ??

Topic blog tags categories 404-error archives Wordpress

Category Web


I know this is an old question but I was having the same issue in a theme I inherited and came across this question in my search for answers.

In my particular case, I found the following PHP code included in the theme's function.php file:

if( is_category() || is_date() || is_author() ) {
   global $wp_query;
   $wp_query->set_404(); //set to 404 not found page
}

This code redirects any category, date, or author archive page to a 404 error (which brings up your 404 theme template). You may want to search for something similar in your theme (assuming you haven't already figured this out).


I've had the same issue. However, I added the following to functions.php file (courtesy: wpbeginner.com) to view my custom post types in categories. WordPress does not display any custom post types in categories until we add the following filter.

add_filter('pre_get_posts', 'query_post_type');
function query_post_type($query) {
  if( is_category() ) {
    $post_type = get_query_var('post_type');
    if($post_type)
        $post_type = $post_type;
    else
        $post_type = array('nav_menu_item', 'post', 'your_post_type_name'); // don't forget nav_menu_item to allow menus to work!
    $query->set('post_type',$post_type);
    return $query;
    }
}

please set permalinks

enter image description here

then after check in category and tag url


Go to your WordPress back-end with this path Settings > Permalinks. Ensure that the base of the category is "category" and the tag is the base "tag" (unless you have some very strange special settings) and just press the "Save Changes" button even if nothing has changed, clicking on the button may cause your category and tag pages to work again.

Don’t forget to clean your WordPress cache for testing.

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.