Use One Archive Template for All Custom Post Type Archives

If you have created multiple custom post types, you can use the same archive-cpt.php template.

By default, you don’t need to create a archive.php template for your custom post type as WordPress will use the standard archive.php file.

If you want to use a unique archive-cpt.php template which is different to what your standard post type uses, you can.

Rather than create a archive-cpt file for each custom post type, simply add this PHP code to your functions file.

Change the example custom post types in the code, portfolio and community to the names of your custom post types and separate them using a comma.

The code above also assumes your custom post type archive file is named archive-cpt.php and resides in the root directory of your theme folder.

Join 5000+ Followers

Get The Latest Free & Premium Tutorials Delivered The Second They’re Published.