Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialJulian Price
11,760 PointsDeconstruct Theme function to Plugin
I have numerous themes that I have purchased over time that I like functionality of options, custom post types, etc.that I want to move to plugin to create my site not dependent on a particular theme.
I've googled to only find what to do when changing themes but not what do to relocate post types to a plugin that's currently in use/integrated with a theme.
Hopefully my questions make sense and welcome Zac Gordon to chime in.
3 Answers
Andrew McCormick
17,730 PointsZac may have a more structured system, but when I pull custom post types (most added features in themes are just custom post-types) from one theme to use in another it's always a bit of hacking away and trial and error. Some themes very clearly register their post types in a file (often in an includes folder sometimes directly in the functions.php file). You can just copy and paste the code to register these same post types in your new theme. If the theme uses a framework it can either be easier or harder. Just try to follow the theme's code logic and track down how the post types are being register.
Some themes are more involved and may require further investigation. Again some plugins that come with themes are stored in an obvious location, some are not.
Just pick a feature and try to track it down. Then fork the code to recreate it.
Julian Price
11,760 PointsThanks. Should I prefix differently or remain the same if not using the same theme avoiding conflict.
Andrew McCormick
17,730 PointsI think that's going to be up to you when dealing with registering the names. If you are doing anything with a database, where a plugin may create a custom table or anything like that, you'll need to have the prefix match the rest of your tables. So you may have to export out that table from your database and then rename it when moving. Pretty sure that's that only place you would run into an issue with prefixes. I haven't done anything that involved creating new tables on the DB, so I'm not 100%
Zac Gordon
Treehouse Guest TeacherZac Gordon
Treehouse Guest Teacher+1 to this approach. Sometimes you just have to track down the code and recreate it yourself in the new theme.