Straw Poll: Where do you set up stuff like CPTs, Shortcodes, thumbnails...?

Just wondering how other people are setting up their roots based themes. I’ve found myself following Roots’ lead and creating new files in /lib like custom_post_types.php, shortcodes.php, thumbnails.php… and then including them all via functions.php.

How are you doing it?

Soil, which is pretty outdated at this point, comes with a ‘base’ mu-plugin for your shortcodes, custom post types and taxonomies.

I think it’s best to place all of those in a mu-plugin or plugin rather than having it associated with the theme. I still use a mu-plugin for site specific functionality like that, along with ACF for custom fields and meta boxes. I’m also now using the ACF options addon instead of using the Options Framework.

For thumbnails, you can set those in lib/init.php

1 Like

Thanks @benword. I should probably do something like that (get my content structure stuff out of the theme). Likely hood of the theme changing on my current project (large non-profit redesign/reboot) is right next to zero but it makes total sense as a best practice.

I’ve been adding a file with my theme name with the other lib files, e.g. /lib/mytheme.php
Then adding that to the list of $roots_includes in functions.php.

I put all my theme specific functionality in there, like additional image sizes, theme support callbacks, custom query hooks etc. I agree that CPT stuff shouldn’t be in the theme (I use ACF and CPTUI), but for me shortcodes are still theme specific functionality, because they usually produce html with some custom styling or js that wouldn’t be available outside the theme.