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 have a custom post type with a custom taxonomy. I don't link to the taxonomy on the page but from the admin anyone can visit the taxonomy/term url and the unstyled list page will be visible. How can I force wp to not use the default layout (index.php) for that listing? What's the best method? For example I creat a taxonomy template and I redirect it to the front page?

share|improve this question

2 Answers 2

If you just want to "turn off" the public facing part of a taxonomy (eg. just use it for grouping), you can do that when you register it.

Just set the query_var argument to false and WordPress will not recognize taxonomy page requests and simply 404. This will work if you don't have pretty permalinks enabled.

<?php
add_action('init', 'wpse94193_register');
function wpse94193_register()
{
    register_taxonomy('your_taxonomy', 'your_post_type', array(
        // other stuff here...
        'query_var' => false,
    ));
}

You can also disable pretty permalinks by setting the rewrite argument to false (props otto).

<?php
add_action('init', 'wpse94193_register');
function wpse94193_register()
{
    register_taxonomy('your_taxonomy', 'your_post_type', array(
        // other stuff here...
        'rewrite'   => false,
        'query_var' => false,
    ));
}

If you do need to allow logged in users to view the taxonomy pages (can't tell from the question), that's different story.

share|improve this answer
1  
This. Also, set the rewrite arg to false as well to disable the permalinks for them too. –  Otto Apr 1 '13 at 23:28
    
setting query_var to false only works when pretty permalinks aren't enabled, you need the rewrite argument as well to cover all bases. deleting my answer and upvoting yours :) –  Milo Apr 1 '13 at 23:47

Check out the Template Hierarchy. If your custom taxonomy is called custom_taxonomy, you should be able to create a template file called taxonomy-custom_taxonomy.php, and it could contain, for instance:

<?php
    wp_redirect( home_url() );
    exit;  // stop processing since we're redirecting
?>

(See the Codex page for wp_redirect() for more on redirecting in WordPress.)

share|improve this answer
    
Yes it was my idea too, what to you think is it the best method? –  hepii110 Apr 1 '13 at 21:16
    
I'd say go with @chrisguitarguy's method -- set the rewrite and query_var to false. My way will work, but his way looks like it's the proper WordPress way to do it. –  Pat J Apr 2 '13 at 13:41

Your Answer

 
discard

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.