• Skip to primary navigation
  • Skip to main content
OsomCode

OsomCode

Awesome code tutorials for WordPress and Genesis

  • Subscribe
  • My account
    • Edit profile
    • Favorites
    • Update credit card
  • Login

Use the same template for a taxonomy as for a CPT archives

Learn in this tutorial how to get WordPress to display the same design in a taxonomy as in the CPT archive pages by code.

If you have created a CPT with a taxonomy or use a plugin that supports it, it is likely that you will want to display it with the same structure that you have chosen for the archive page (for example, in grid format).

Do you want to save the step of creating a new template just for this?

Then use the conditional tags and tell WordPress to use the existing one.

Here are the exact instructions:

Snippet to redirect the taxonomy to a CPT archive template

Add the following code at the end of functions.php or in your functionality plugin:

To see this and another 847 code snippets of this website, login or subscribe here.

It’s as simple as that. Now when you visit the taxonomy of a CPT the template you use for the archive page of the CPT will be loaded.

In the previous code you have the example CPT “portfolio”, but you can change both the CPT and the taxonomy to suit your needs.

Conclusion

As you can see, with a few lines of code you can save yourself from having to create a new template for your CPT taxonomy.

Any questions? I read you in the comments.

And if you want to give me any suggestion for future tutorials, leave it in the contact form. Advantages of being a subscriber. 😉

CPT PHP WordPress

To leave read and make questions about this code, you can login or register.

  • About OsomCode
  • FAQ
  • Contact

Legal Notice · Privacy Policy · Cookie Policy · Terms and conditions
Copyright © 2023

Lost your password?