0

I wanted to disable category archive pages because content in my blog will be presented via a number of pages for which I have custom templates like this:

add_action('page_template', 'select_page_template');

function select_page_template($template)
{
    $pageName = get_query_var('pagename');

    if ($pageName == "about")
        $page_template = TEMPLATEPATH . '/page-templates/about.php';

    return $page_template;
}


To do what I wanted, I coded the below so as to redirect all calls from http://www.mydomain.com/[CATEGORY-SLUG] to the 404.php page of the blog:

add_action('category_template', 'select_category_template');

function select_category_template($template)
{
    header("HTTP/1.0 404 Not Found");
    $GLOBALS['wp_query']->is_404 = TRUE;
    return TEMPLATEPATH . '/404.php';
}


Does it make sense, especially in respect to SEO? In theory, like this I'm getting the same result I get if I visit a no-page like: http://www.mydomain.com/abcdef

  • You could use template_include or replace your themes category.php file with a custom file in a child theme. The filter is actually add_filter('category_template', 'select_category_template'); – Brad Dalton Aug 7 '14 at 8:02
  • But that would not fire a 404 response status code, it will be 200, or I'm wrong? – WPRookie82 Aug 7 '14 at 8:03
  • You can add the is_404() conditional after any function but is that the best solution? – Brad Dalton Aug 7 '14 at 8:20
  • I'm not calling is_404(), the code inside function select_category_template($template) is working like a charm, just making sure that it's the cleanest way to achieve what I want. As a matter of fact, my select_category_template function code is working for all category pages. – WPRookie82 Aug 7 '14 at 8:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.