How to get current get_post_types name?

You’ll need the post object somehow, or, alternatively the queried object on post type archives. On a singular page you might do:

$post = get_queried_object();
$postType = get_post_type_object(get_post_type($post));
if ($postType) {
    echo esc_html($postType->labels->singular_name);
}

Or in the loop:

$postType = get_post_type_object(get_post_type());
if ($postType) {
    echo esc_html($postType->labels->singular_name);
}

In post type archives:

$postType = get_queried_object();
echo esc_html($postType->labels->singular_name);

All of these will give you the singular name of the post type that was registered in register_post_type‘s labels key.

Leave a Comment