How to Register Custom Post Types with Six/Ten Press

Registering custom post types in WordPress isn’t really that hard, but working through sites with multiple custom types can get tedious, so Six/Ten Press sets up basic post type and taxonomy registration classes, with some opinionated choices added in. With Six/Ten Press activated, to register a custom post type for a resource directory, for example, you could just do this:

add_action( 'sixtenpress_setup', 'prefix_register_resource_post_type' ); /** * Register a resource custom content type with custom labels, icon, and taxonomy. * Requires Six/Ten Press 2.1.0. */ function prefix_register_resource_post_type() { $post_type = 'resource'; $args = array( 'labels' => array( 'singular' => __( 'Resource', 'prefix' ), 'plural' => __( 'Resources', 'prefix' ), ), 'menu_position' => 10, 'menu_icon' => 'dashicons-schedule', 'taxonomies' => array( 'audience' ), ); sixtenpress_register_post_type( $post_type, $args ); } add_action( 'sixtenpress_setup', 'prefix_register_resource_taxonomy' ); /** * Register an audience taxonomy with custom labels for use with the resource content type. * Requires Six/Ten Press 2.1.0 */ function prefix_register_resource_taxonomy() { $taxonomy = 'audience'; $args = array( 'labels' => array( 'singular' => __( 'Audience', 'prefix' ), 'plural' => __( 'Audiences', 'prefix' ), ), ); sixtenpress_register_taxonomy( $taxonomy, 'resource', $args ); }
Code language: PHP (php)

Everything in the post type and taxonomy registry is filterable, and can be modified as you register the post type, or by using the filter. For the resource post type, we’ve modified the menu position, icon, and taxonomies as part of the registration process.

The filters all follow the same pattern:

  • sixtenpress_{$post_type['post_type']}_labels becomes sixtenpress_resource_labels, so if you want to modify the labels built during the post type registration, you can.
  • sixtenpress_{$post_type['post_type']}_rewrite becomes sixtenpress_resource_rewrite, to modify the slug. etc. for the post type output.
  • sixtenpress_{$post_type['post_type']}_supports becomes sixtenpress_resource_supports; it returns an array of standard support items for the custom content type (title, editor, excerpts, thumbnails/featured images, Genesis archive settings).
  • sixtenpress_{$post_type['post_type']}_args becomes sixtenpress_resource_args; this filters everything about the new custom post type, and will override the first three filters.
Return to Six/Ten Press