I want to use a certain archive template for a bunch of different parent categories. Therefor I try to change the archive template by using the 'archive_template'
filter in functions.php by identifying what slug the current category has.
I've tried to retrieve the category slug by using three different methods as you can see below, but none of them seem to work. What's the correct way of retrieving the current category in functions.php?
function use_custom_template($tpl){
global $post;
$tryOne = get_the_category( $post->ID );
$tryTwo = get_the_category();
$tryThree = get_queried_object();
if (is_tax("sport-fritid-parent") {
$tpl = dirname( __FILE__ ) . '/category-custom-parent.php';
}
return $tpl;
}
add_filter( 'archive_template', 'use_custom_template' ) ;
require
orget_template_part
in that file if you need to share the code across multiple files