I copied this code from a youtuber. It works for him, but not for me. Does the code contain any errors? As soon as I put it in, my WordPress breaks and won’t load.
function gt_custom_post_type() {
register_post_type('project',
array(
'rewrite' => array('slug' => 'projects'),
'labels' => array(
'name' => 'Projects'
'singular_name' => 'Project',
'add_new_item' => 'Add New Project',
'edit_item' => 'Edit Project'
),
'menu-icon' => 'dashicons-media-document',
'public' => true,
'has_archive' => true,
'supports' => array(
'title', 'thumnail', 'editor', 'excerpt', 'comments'
)
)
);
}
add_action('init', 'gt_custom_post_type');
I copied this code from a youtuber. It works for him, but not for me. Does the code contain any errors? As soon as I put it in, my WordPress breaks and won’t load.
function gt_custom_post_type() {
register_post_type('project',
array(
'rewrite' => array('slug' => 'projects'),
'labels' => array(
'name' => 'Projects'
'singular_name' => 'Project',
'add_new_item' => 'Add New Project',
'edit_item' => 'Edit Project'
),
'menu-icon' => 'dashicons-media-document',
'public' => true,
'has_archive' => true,
'supports' => array(
'title', 'thumnail', 'editor', 'excerpt', 'comments'
)
)
);
}
add_action('init', 'gt_custom_post_type');
There are many small problems with this code (see my comments below):
function gt_custom_post_type() {
register_post_type('project',
array(
'rewrite' => array('slug' => 'projects'),
'labels' => array(
'name' => 'Projects', // <- missing comma
'singular_name' => 'Project',
'add_new_item' => 'Add New Project',
'edit_item' => 'Edit Project'
),
'menu-icon' => 'dashicons-media-document',
'public' => true,
'has_archive' => true,
'supports' => array(
'title', 'thumbnail', 'editor', 'excerpt', 'comments' // <- thumbnail not thumnail
)
)
);
}
add_action('init', 'gt_custom_post_type');
Also you’re lacking any internationalization in there...
I'd recommend using this resource for getting custom post type code to add to your functions.php: https://generatewp/post-type/ If you're finding that you're still running into errors after using that code, then the issue is likely how you're adding it to your functions.php file.
There's also a great plugin called Custom Post Types.