Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I don't want to support Categories in my WordPress site.

I know I can have an empty category.php page to cater for users using a URL to directly query the default Category (/category/Uncategorized), but I was wondering if there's a way to shut off WordPress's recognition of the category URLs, so that any attempt to access them would direct to the 404 page?

Thanks.

share|improve this question
add comment

3 Answers

Look at the code @scribu suggested for a function unregister_taxonomy_from_object_type($taxonomy, $object_type) (the last patch currently).
Until the code has found its way into the core, add it to your functions.php, wrap it into a function_exists() and call it on init.

unregister_taxonomy_from_object_type( 'category', 'post' );
share|improve this answer
add comment

I'd choose the way that @toscho suggested.

Anyway here's a solution that completely removes the built in taxonomy. I wouldn't adivse you to use it (may cause unexpected behavior).

/**
 * Remove built in taxonomies
 */
function unregister_taxonomy( $taxonomy ) 
{
    global $wp_taxonomies;

    // Here we can take a separated look at the built in taxonomies
    echo '<pre>';
        /*
        print_r( $wp_taxonomies['category'] );
        print_r( $wp_taxonomies['post_tag'] );
        print_r( $wp_taxonomies['nav_menu'] );
        print_r( $wp_taxonomies['link_category'] );
        print_r( $wp_taxonomies['post_format'] );
        */

    foreach ( $wp_taxonomies as $tax => $data )
    {
        // Only deal with _builtin taxonomies
        if ( $data->_builtin === true )
        {
            // Print out them name if it's builtin; check
            # print_r( $tax ); 

            // Now let's unset "category"
            if ( $tax == 'category')
            {
                // Check to be sure if we're dealing with the right one
                # print_r( $tax );
                unset( $wp_taxonomies[$tax] );
            }
        }
    }
    // double check after wards: have we been successful?
    # print_r($wp_taxonomies);
    echo '</pre>';
}
add_action( 'init', 'unregister_taxonomy' );

function check_unset_category() {
    // Now let's check inside our viewport (after footer) if we real got rid of the taxonomy
    echo '<pre>';
        print_r( $GLOBALS['wp_taxonomies'] );
    echo '</pre>';
}
add_action( 'wp_footer', 'check_unset_category', 999 );
share|improve this answer
add comment

I don't know offhand if it is possible to "shut off" category's in WordPress, but you can accomplish what your asking for with simple .htaccess rewrite rules.

for instance for just the /category

RedirectMatch 301 ^/category/$ http://example.com/404.html

for all sub-directory's and pages linked through /category/*

RedirectMatch 301 ^/category/.*$ http://example.com/404.html

You want to use a 301 to tell Google and such that it is a permanent change. Also I suggest instead of sending them to a 404 page just send requests to the home page if the site link has never existed, if it has and is linked then a 404 page with useful info.

ps. the syntax highlighter makes the above have weird colors.

share|improve this answer
    
Thanks Wyck, that looks like a good approach. –  user4184 Mar 26 '11 at 23:29
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.