• Skip to main content
  • Skip to forum navigation

StudioPress

  • Shop for Themes
  • My StudioPress

Forum navigation

  • Home
  • General Genesis Discussions
  • StudioPress Themes
  • Genesis Blocks
    • Genesis Blocks
    • Genesis Custom Blocks
  • Retired Themes
  • FAQs
  • Forum Rules
  • Internationalization and Translations
  • Forum Bugs and Suggestions
  • Forum Log In

Are You Using The WordPress Block Editor?

Genesis now offers plugins that help you build better sites faster with the WordPress block editor (Gutenberg). Try the feature-rich free versions of each plugin for yourself!

Genesis Blocks Genesis Custom Blocks

Moving custom post type code from functions.php to cpt template?

Welcome!

These forums are for general discussion on WordPress and Genesis. Official support for StudioPress themes is offered exclusively at My StudioPress. Responses in this forum are not guaranteed. Please note that this forum will require a new username, separate from the one used for My.StudioPress.

Log In
Register Lost Password

Community Forums › Forums › Archived Forums › Design Tips and Tricks › Moving custom post type code from functions.php to cpt template?

This topic is: not resolved

Tagged: custom post types

  • This topic has 3 replies, 3 voices, and was last updated 12 years ago by ameeker.
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • January 12, 2014 at 10:20 am #84775
    ameeker
    Member

    I have code for displaying a custom post type currently in the functions.php file - I'm wondering if I can move it to a template for the single-(post-type).php instead (single-tipoftheday.php in this case). I will have several other CPT's to format and think this will make it easier for the client to eventually modify these if they need to. Will those functions still work that way? Here is a paste of what I expect the template would be.

    http://pastie.org/8626678

    (Displaying the custom fields works in functions.php - I'm not necessarily asking for a review of THAT - but rather if it will continue to work as a template instead of in functions, and if this is a good practice).


    Looking for Genesis website design backed by strategy? http://www.angiemeekerdesigns.com

    January 12, 2014 at 3:26 pm #84828
    cdils
    Participant

    Not sure if I understand correctly, but it's too late to register the CPT by the time you're in a template page.

    I'd pull all the CPTs out into a single file (call it my-theme-cpts.php or something equally obvious) and then include that file in functions.php. It'll keep your code a little cleaner.

    Then you can still do your template files as is, except you won't need the conditionals (i.e. no need to check if it's a single page if you're already in single-tipoftheday.php.

    I may have completely missed your question. If so, try me again. 🙂


    Have you been helped in this forum? Pay it forward and answer someone else’s question. I bet you’ll know the answer to at least one question. 🙂

    I host a weekly WordPress-focused podcast called Office Hours. I tweet @cdils.

    January 12, 2014 at 6:44 pm #84863
    Sridhar Katakam
    Participant

    My personal preference is to use a plugin for managing the CPTs.


    Genesis Tutorials | Follow me on Twitter

    January 12, 2014 at 7:14 pm #84872
    ameeker
    Member

    I already have the CPT's defined (using the Custom Post Type UI plugin so the clients can more easily manage them in the future).


    @Carrie
    - so the rest of the paste, minus the conditional to check for the CPT, the it would work as it is in single-tipsoftheday.php ?

    I've got the entire part about displaying custom fields in the functions.php file now.


    Looking for Genesis website design backed by strategy? http://www.angiemeekerdesigns.com

  • Author
    Posts
Viewing 4 posts - 1 through 4 (of 4 total)
  • The forum ‘Design Tips and Tricks’ is closed to new topics and replies.

CTA

Ready to get started? Create a site or shop for themes.

Create a site with WP EngineShop for Themes

Footer

StudioPress

© 2026 WPEngine, Inc.

Products
  • Create a Site with WP Engine
  • Shop for Themes
  • Theme Features
  • Get Started
  • Showcase
Company
  • Brand Assets
  • Terms of Service
  • Accptable Usse Policy
  • Privacy Policy
  • Refund Policy
  • Contact Us
Community
  • Find Developers
  • Forums
  • Facebook Group
  • #GenesisWP
  • Showcase
Resources
  • StudioPress Blog
  • Help & Documentation
  • FAQs
  • Code Snippets
  • Affiliates
Connect
  • StudioPress Live
  • StudioPress FM
  • Facebook
  • Twitter
  • Dribbble