# Use pre-existing base template for taxonomy archive and custom post type

**URL:** https://discourse.roots.io/t/use-pre-existing-base-template-for-taxonomy-archive-and-custom-post-type/12527
**Category:** sage
**Tags:** sage8
**Created:** 2018-05-22T14:33:09Z
**Posts:** 5

## Post 1 by @joneslloyd — 2018-05-22T14:33:09Z

Hi all,

(I’m using Sage 8 on a legacy site).

I have (what I think is) a unique issue / use-case:

I have a Custom Post Type `hub_resource` and a Taxonomy called `hub_topic`.

I want both of these to use a base template I’ve defined, called `base-template-hub.php`.

Doing this for the `hub_resource` CPT is easy enough; I just have a `template-hub.php` file with this in the header:

```
<?php
/**
 * Template Name: Hub
 * Template Post Type: hub_resource
 */
?>
```

But trying to get the `hub_topic` Taxonomy to use this same base template is seemingly impossible.

Does anybody have any ideas?

Cheers,  
Lloyd

---

## Post 2 by @joneslloyd — 2018-05-22T17:43:27Z

FIXED:

- Created `base-taxonomy-hub_topic.php`
- Filled it with the following:

```
<?php
include 'base-template-hub.php';
```

Thanks to @bokorir

---

## Post 3 by @mmirus — 2018-05-22T17:56:42Z

Hey @joneslloyd - a couple of ideas:

First, you could step back and do conditional login in your base.php file to check if the current request is for your CPT or taxonomy and load the correct wrapper template if true.

Second, the `SageWrapping` class (which returns the appropriate wrapper) applies a filter prior to returning the wrapper template. I haven’t tried it, but it looks like you could hook into that.

From `wrapper.php`:

```
public function __toString() {
  $this->templates = apply_filters('sage/wrap_' . $this->slug, $this->templates);
  return locate_template($this->templates);
}
```

So maybe something like (untested):

```
function hub_taxonomy_wrapper($templates) {
  if (is_tax('hub_topic')) {
    array_unshift($templates, 'base-template-hub.php');
  }
  return $templates;
}
add_filter('sage/wrap_base', __NAMESPACE__. '\\hub_taxonomy_wrapper');
```

---

## Post 4 by @joneslloyd — 2018-05-23T07:43:33Z

Hey @mmirus – Thanks for this! Will give it a go.

---

## Post 5 by @joneslloyd — 2018-05-23T07:48:06Z

That works really well :slight_smile:

```
/**
 * Force hub_topic taxonomy to use the base-template-hub.php template
 */
function hub_taxonomy_wrapper($templates)
{
    if (is_tax('hub_topic')) {
        array_unshift($templates, 'layouts/base-template-hub.php');
    }
    return $templates;
}
add_filter('sage/wrap_base', __NAMESPACE__. '\\hub_taxonomy_wrapper');
```
