0

I am organizing and cleaning my code to make it easier to maintain. It turns out that my site has a lot of custom post types, so I have about fifteen single-***.php files at the root of my site. In order to make the tree view cleaner, I would like all of these files to be listed in a specific "single" folder.

Obviously, Wordpress only recognizes the single-***.php files that are at the root of a theme. Is there a way around this?

Thanking you in advance for your help.

2

Changing how WordPress loads files can be very difficult and potentially destroy logic other plugins rely on. Instead, I usually make use of get_template_part() in this case like so

single.php

<?php

get_template_part('singles/single', get_post_type());

And your files like

  • singles/single-foo.php (for CPT foo)
  • singles/single-bar.php (for CPT bar)
  • singles/single.php (this is the default)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.