Custom Post Types

We have a number of CPT created for all scenarios, these follow the following format.

<?php 
$singular_name = 'component';
$singular_label = 'Component';
$plural_label = 'Components';
$menu_icon = 'dashicons-index-card';
$taxonomies = array();
$supports = array('title', 'thumbnail', 'editor', 'custom-fields', 'revisions');
$labels = array(
    'name'					=> _x( $plural_label, 'post type general name' ),
    'singular_name'			=> _x( $singular_label, 'post type singular name' ),
    'menu_name'				=> _x( $plural_label, 'admin menu' ),
    'name_admin_bar'		=> _x( $singular_label, 'add new on admin bar'),
    'add_new'				=> _x( 'Add New', $singular_label ),
	'add_new_item'			=> __( 'Add New ' . $singular_label ),
    'new_item'				=> __( 'New ' .$singular_label . ' name' ),
    'edit_item'				=> __( 'Edit ' . $singular_label ),
    'view_item'				=> __( 'View ' . $singular_label),
    'all_items'				=> __( 'All ' . $plural_label),
    'search_items'			=> __( 'Search ' . $plural_label),
    'parent_item_colon'		=> __( 'Parent ' . $plural_label . ':'),  
    'not_found'				=> __( 'No ' . $plural_label . ' found' ),
    'not_found_in_trash'	=> __( 'No ' . $plural_label . ' found in Trash' ),  
);    
$post_type_args = array(
    'public'				=> true,
    'publicly_queryable'	=> true,
    'exclude_from_search'	=> true,
    'map_meta_cap'			=> true,
    'show_ui'				=> true,
    'show_in_menu'			=> true,
    'query_var'				=> true,
    'has_archive'			=> true,
    'hierarchical'			=> false, 
    'show_in_rest'			=> true, 
    'menu_position'			=> 5,
    'labels'				=> $labels,
    'description'			=> __( ''),
    'menu_icon'				=> $menu_icon,
    'supports'				=> $supports,
    'taxonomies'			=> $taxonomies
    'rewrite'				=> array('slug' => $singular_name, 'with_front' => true ),
    'capability_type'		=> 'post',
 );
register_post_type($singular_name ,$post_type_args);
?>

These are simply included in the theme functions.php

<?php 
if ( ! function_exists( 'gomo_cpt_init' ) ) :
	function gomo_cpt_init() {
		if( get_field('remove_admin_scripts', 'options') == 0 ):
			require get_template_directory() . '/gomo-functions/admin.php';
		endif;
		require get_template_directory() . '/gomo-functions/custom-post-types/documentation.php' ;
		require get_template_directory() . '/gomo-functions/custom-post-types/components.php' ;
		require get_template_directory() . '/gomo-functions/custom-post-types/testimonials.php' ;
		require get_template_directory() . '/gomo-functions/custom-post-types/listings.php' ;
		require get_template_directory() . '/gomo-functions/custom-post-types/panel.php' ;
		require get_template_directory() . '/gomo-functions/custom-post-types/case-studies.php' ;
		require get_template_directory() . '/gomo-functions/acf/acf.php' ;
		require get_template_directory() . '/gomo-functions/custom-taxonomy/resources.php' ;
		require get_template_directory() . '/gomo-functions/custom-taxonomy/listings.php' ;
		require get_template_directory() . '/gomo-functions/custom-taxonomy/case-studies.php' ;
	}
endif;
add_action( 'init', 'gomo_cpt_init' ); 
?>

Search the site


Address

123 Main Street
Town
City
P05T C0D3

Tel: 01234 567 899

Mob: 01234 567 899

Email: ben@gomopress.com


Copyright 2023. Blah blah blah Company Limited