How to get custom post type label and singular label from its slug?

get_post_type_object() will return, as the name suggests, an object that contains the post type information.

You may want to var_dump() it to inspect it contents. You’ll see that it includes (among other stuff) another object, labels that contains all the registered labels for the specific post type.

$pt = get_post_type_object( 'books' );

// These two usually contain the post type name in plural. 
// They may differ though.
echo $pt->label;
echo $pt->labels->name;

// This one holds the post type name in singular.
echo $pt->labels->singular_name;

Leave a Comment