0

I am trying to over-ride a custom taxonomy file from my plugin. Actually, I have 2 custom taxonomies: destination & activities. I have successfully over-ridden the taxonomy template for activities but for destination is_tax() function is not working. That is why I am unable to over-ride the taxonomy template for destination. Everything including slug is absolutely correct. Tried this as well: Template redirect is_tax() not working On body tag, this is the class that is displayed on failed state: hfeed image-filters-enabled

Below is my function:

function abc( $template_path ) {
    if( is_tax( 'destination' ) )
    {
        $template_path = locate_template( array( 'taxonomy-destination.php' ) );

        // LOOK IN MAIN PLUGIN
        if( !$template_path )
        {
            $template_path = WP_TRAVEL_ENGINE_TEMPLATE_PATH . '/taxonomy-destination.php';
        }

        // OVER-RIDE FROM CURRENT PLUGIN
        if( $template_path )
        {
            $template_path = WP_TRAVEL_ENGINE_VENDOR_BASE_PATH . '/public/vendor-templates/page-templates/taxonomy-destination.php';
        }
        return $template_path;
    }
    if( is_tax( 'activities' ) )
    {
        $template_path = locate_template( array( 'taxonomy-activities.php' ) );

        // LOOK IN MAIN PLUGIN
        if( !$template_path )
        {
            $template_path = WP_TRAVEL_ENGINE_TEMPLATE_PATH . '/taxonomy-activities.php';
        }

        // OVER-RIDE FROM CURRENT PLUGIN
        if( $template_path )
        {
            $template_path = WP_TRAVEL_ENGINE_VENDOR_BASE_PATH . '/public/vendor-templates/page-templates/taxonomy-activities.php';
        }
        return $template_path;
    }
    return $template_path;
}
add_filter( 'template_include','abc' );

This is how taxonomy is registered:

$labels = array(
            'name'              => _x( 'Destinations', 'taxonomy general name', 'wp-travel-engine' ),
            'singular_name'     => _x( 'Destinations', 'taxonomy singular name', 'wp-travel-engine' ),
            'search_items'      => __( 'Search Destinations', 'wp-travel-engine' ),
            'all_items'         => __( 'All Destinations', 'wp-travel-engine' ),
            'parent_item'       => __( 'Parent Destinations', 'wp-travel-engine' ),
            'parent_item_colon' => __( 'Parent Destinations', 'wp-travel-engine' ),
            'edit_item'         => __( 'Edit Destinations', 'wp-travel-engine' ),
            'update_item'       => __( 'Update Destinations', 'wp-travel-engine' ),
            'add_new_item'      => __( 'Add New Destinations', 'wp-travel-engine' ),
            'new_item_name'     => __( 'New Destinations Name', 'wp-travel-engine' ),
            'menu_name'         => __( 'Destinations', 'wp-travel-engine' ),
        );

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

        register_taxonomy( 'destination', array( 'trip' ), $args );

Any help would be more than appreciable.

6
  • And how is the taxonomy registered? – Krzysiek Dróżdż Feb 18 '19 at 8:29
  • @KrzysiekDróżdż Thanks for reply. I have added that in my question now. – saurav.rox Feb 18 '19 at 8:32
  • Try adding var_dump( get_queried_object() ); at the top of your abc() function and see if the result shows a valid term object. If not, you may need to add wp_reset_query(); to reset the global WP_Query instance. – Sally CJ Feb 18 '19 at 9:26
  • @SallyCJ Even if I add die() just after function abc( $template_path ) { , the function is not dying or its is not being called. Admin bar disappears as well when destination template is tried to access. – saurav.rox Feb 18 '19 at 9:35
  • How are you attempting to view destinations? Are you certain the URL you're visiting is a taxonomy archive? – Jacob Peattie Feb 18 '19 at 11:11

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.