jenhuls
6/24/2016 - 6:38 PM

WordPress Custom Post Type plugin

WordPress Custom Post Type plugin

<?php
/*
Plugin Name: Theme Name Custom Post Types
Description: Custom Post Types for Theme Name Custom theme.
Author: [Jen Huls]
Author URI: 
*/

// Theme Name: Custom Post Types
add_action( 'init', 'theme_name_cpt' );

function theme_name_cpt() {

	register_post_type( 'post_type_name', array(
	  'labels' => array(
	    'name' => 'Post Type Name',
	    'singular_name' => 'Post Type Name',
	   ),
	  'description' => 'Post Type Name details.',
	  'public' => true,
	  'menu_icon' => 'dashicons-',
	  'menu_position' => 20,
	  'capability_type' => 'post',
	  'supports' => array( 'title', 'content' ),
	  'rewrite' => array(
	    'slug' => 'post-type-slug',
	    'with_front' => FALSE,
	  ),
	));
}
// Theme Name: Change default title text
function post_type_change_default_title( $title ){
    $screen = get_current_screen();
    if ( 'post_type' == $screen->post_type ){
        $title = 'Post Type Title';
    }
    return $title;
}
add_filter( 'enter_title_here', 'post_type_change_default_title' );

// Theme Name Theme: CPT Post Labels
function change_post_type_labels() {
  global $wp_post_types;

  // Get the 'Training' post labels
  $postLabels = $wp_post_types['post_type']->labels;
  $postLabels->name = 'Post Type Name';
  $postLabels->singular_name = 'Post Type Name';
  $postLabels->add_new = 'Add New Post Type Name';
  $postLabels->add_new_item = 'Add New Post Type Name';
  $postLabels->edit_item = 'Edit Post Type Name';
  $postLabels->new_item = 'Post Type Names';
  $postLabels->view_item = 'View Post Type Names';
  $postLabels->search_items = 'Search Post Type Names';
  $postLabels->not_found = 'No Post Type Names found';
  $postLabels->not_found_in_trash = 'No Post Type Names found in Trash';
  
}
add_action( 'init', 'change_post_type_labels' );