2024 Custom Taxonomy Template for Gutenberg Blocks

This post will give you a simple way to create custom templates for custom taxonomy term archives. The solution assumes you’re using the site editor with a theme like Twenty Twenty Four or other modern block theme but won’t work with the old PHP coded templates.

The good news, it will work with the WordPress template hierarchy when it comes to your taxonomy slugs. Its out with .php template files and in with .html files.

Copy over your archive.html template to your child theme and rename it to the slug you’ve used to create your custom taxonomy. Also, make sure the file is inside the templates folder in your child themes root directory.

So all you need is a folder named templates and a file inside named taxonomy-slug.html where slug is the slug used to register your taxonomy. I named the file taxonomy-event.html. Thats all there is to it.

If you don’t create this file, your custom taxonomy and term archive pages will not render any HTML markup. Without HTML markup, no styling.

Here’s the PHP code i used in my child themes functions.php file to register the custom taxonomy :

add_action( 'init', 'custom_event_taxonomy' );
function custom_event_taxonomy() {

    $labels = array(
        'name'                       => _x( 'Events', 'taxonomy general name', 'textdomain' ),
        'singular_name'              => _x( 'Event', 'taxonomy singular name', 'textdomain' ),
        'search_items'               => __( 'Search Events', 'textdomain' ),
        'popular_items'              => __( 'Popular Events', 'textdomain' ),
        'all_items'                  => __( 'All Events', 'textdomain' ),
        'parent_item'                => __( 'Parent Event', 'textdomain' ),
        'parent_item_colon'          => __( 'Parent Event:', 'textdomain' ),
        'edit_item'                  => __( 'Edit Event', 'textdomain' ),
        'update_item'                => __( 'Update Event', 'textdomain' ),
        'add_new_item'               => __( 'Add New Event', 'textdomain' ),
        'new_item_name'              => __( 'New Event Name', 'textdomain' ),
        'separate_items_with_commas' => __( 'Separate events with commas', 'textdomain' ),
        'add_or_remove_items'        => __( 'Add or remove events', 'textdomain' ),
        'choose_from_most_used'      => __( 'Choose from the most used events', 'textdomain' ),
        'menu_name'                  => __( 'Events', 'textdomain' ),
    );

    $args = array(
        'hierarchical'          => true,
        'show_in_rest'          => true,
        'labels'                => $labels,
        'show_ui'               => true,
        'show_admin_column'     => true,
        'query_var'             => true,
        'rewrite'               => array( 'slug' => 'event' ),
    );

    register_taxonomy( 'event', 'product', $args );
}

I assume this method would also work for custom post type archives and single custom post types.

Category Pages

You can customize product category pages in WooCommerce using this template. No need for any plugins.

Need More Coding Help?

Book a Consultation

Was This Tutorial Helpful?

Free

$0

Access only to all free tutorials per month.



Monthly

$75

Access to 10 premium tutorials per month.


Tutorial Request


Includes code guarantee and coding support.

Yearly

$500

Access to 15 premium tutorials per month.


Monthly Tutorial Request


Includes code guarantee and priority coding support.