Last active
January 20, 2016 00:23
-
-
Save benwo/6e8e9cbe92babaf552b1 to your computer and use it in GitHub Desktop.
Wordpress - Custom Post Type template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Example basic template for setting up a post type called 'Project' | |
function cpt_project() { | |
$labels = array( | |
'name' => _x( 'Projects', 'post type general name' ), | |
'singular_name' => _x( 'Project', 'post type singular name' ), | |
'add_new' => _x( 'Add New', 'project' ), | |
'add_new_item' => __( 'Add New Project' ), | |
'edit_item' => __( 'Edit Project' ), | |
'new_item' => __( 'New Project' ), | |
'all_items' => __( 'All Projects' ), | |
'view_item' => __( 'View Project' ), | |
'search_items' => __( 'Search Project' ), | |
'not_found' => __( 'No projects found' ), | |
'not_found_in_trash' => __( 'No projects found in the Trash' ), | |
'parent_item_colon' => '', | |
'menu_name' => 'Projects' | |
); | |
$args = array( | |
'labels' => $labels, | |
'description' => 'Projects I want to showcase on my website', | |
'public' => true, | |
'menu_position' => 3, | |
'menu_icon' => 'dashicons-admin-customizer', | |
'supports' => array( 'title', 'editor', 'thumbnail' ), | |
'taxonomies' => array('category', 'post_tag'), | |
'has_archive' => true | |
); | |
register_post_type( 'project', $args ); | |
} | |
add_action( 'init', 'cpt_project' ); | |
// Fix post type placeholder title | |
function wpb_change_title_text( $title ){ | |
$screen = get_current_screen(); | |
if ( 'project' == $screen->post_type ) { | |
$title = "Enter the project title"; | |
} | |
return $title; | |
} | |
add_filter( 'enter_title_here', 'wpb_change_title_text' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment