I created a taxonomy.php template that works fine for the default stuff, but I realized my theme has default'd to index.php when trying to load a custom taxonomy I created (IE: open website.com/age/something in my browser). According to the Template Hierarchy, it should work? Here is how it's created:

function custom_events_taxonomy() {

$labels = array('name' => _x( 'Ages', 'taxonomy general name' ),
  'singular_name' => _x( 'Age', 'taxonomy singular name' ),
  'search_items' =>  __( 'Search Age' ),
  'all_items' => __( 'All Ages' ),
  'parent_item' => __( 'Parent Age' ),
  'parent_item_colon' => __( 'Parent Age:' ),
  'edit_item' => __( 'Edit Age' ),
  'update_item' => __( 'Update Age' ),
  'add_new_item' => __( 'Add New Age' ),
  'new_item_name' => __( 'New Age Name' ),
  'menu_name' => __( 'Ages' ),

// Now register the taxonomy
  register_taxonomy( 'age', array( 'post' ), array(
    'hierarchical' => true,
    'labels' => $labels,
    'show_ui' => true,
    'query_var' => true,
    'rewrite' => array( 'slug' => 'age' ),
add_action( 'init', 'custom_events_taxonomy', 0 );

During troubleshooting, I was looking into template-loader.php and saw that when it runs the is_tax() method, it returns false. Not sure what I missed or if I am approaching this incorrectly.

What I'd like to happen is Wordpress to use my taxonomy.php for these custom taxonomies I register, but I cannot figure out why is_tax() returns false.

  • What do you mean by "when trying to load a custom taxonomy I created"? Are you going to website.com/age/something? How do you know it's using index.php and not taxonomy.php? – Jacob Peattie Oct 5 '17 at 13:59
  • Yes, exactly. I go to a url similar to what you suggest, and it loads a list of posts instead of the thumbnail rows I made. I did a var_dump in both taxonomy.php and index.php and the output came from index.php. When I used a debugger, I stepped through the code, and saw is_tax() is returning false. – Nathan Oct 5 '17 at 14:08
  • Have you cleared your permalinks yet after creating your taxonomy? – socki03 Oct 5 '17 at 14:22
  • I went and changed the permalinks, saved, and then changed them back and saved again if that clears them. – Nathan Oct 5 '17 at 14:23
  • 1
    FYI, usually all you have to do to clear your permalinks is visit the permalinks page. It has a function built into it called flush_rewrite_rules that cleans/creates new permalink structures. – socki03 Oct 5 '17 at 16:27

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.