Add Custom Post Type To Any Theme

This code enables you to create a Custom Post Type in any WordPress theme.

members custom post type

Simply copy the PHP code from the view raw link and paste it at the end of your child themes functions.php file using a text editor like Notepad++.

Once you’ve added the code, go to Settings > Permalinks and re-save your Permalinks which flushes the cache for your re-write rules.

The code also creates:

  • An archive page with pagination to list your single custom post type pages
  • Support for adding custom taxonomy types (which are like categories for custom post types)

If you don’t want to add support for creating custom taxonomy types, you can replace this line of code:

'taxonomies'   => array( 'member-type' ),

With this code which enables you to create categories for your CPT:

'taxonomies'   => array( 'category' ),

Change Name of Custom Post Type (CPT)

You can easily change the name of your custom post type simply by changing all instances of member and members to whatever you like and then re-save your permalinks.

Add Pagination to CPT Archive Pages

This PHP code, once added to your functions.php file, enables you to determine how many CPT items display on your archive page. If you have added 12 items and this code includes 6, then page navigation will be added to the end of the archive to link to page 2 which contains the other 6 CPT items.

Simply replace Your CPT Name in the code with the name of your custom post type and re-save your Permalink settings.

Change Layout

You can change the layout of your custom post type archive page or single post template for custom post types using code directly in a template file for your CPT or using a custom function to conditionally change the layout.

Unlike standard posts and pages, a custom post type Edit screen does not include layout settings.

Themes Which Include Custom Post Type Support

You can also easily add a CPT with portfolio style archive page to any StudioPress theme.

Here’s an example of what the Lifestyle Pro theme looks like once you’ve added a Custom Post Type with Portfolio style page.

Other themes from StudioPress like the Executive Pro & Minimum Pro themes already include a custom post type with taxonomy type support and Portfolio page template.

More Tips When Using Custom Post Types

Never Miss a Tip from WP Sites

Get my latest web design tutorials, elegant coding solutions & useful tips.

5 Reasons Mad Mimi Works Better

mad-mimi
  1. Sends From Your Email Address - More personal & higher open rate
  2. Cheapest - $42 for list of 10,000 emails, unlimited sends
  3. Ease of Use - The easiest system to create & setup campaigns
  4. RSS to E-Mail - Auto send list of latest posts
  5. Auto Send Any Number of Days - enables you to offer multiple newsletters at different frequencies.

Click here to create a free account.

Leave a Reply

Your feedback is always appreciated.

Your feedback is always welcome & appreciated however WP Sites does not reply to anonymous comment authors or approve loaded questions. Members get answers to unlimited questions.