Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save yuriitaran/84aee2faf3b514458f2656f16d659987 to your computer and use it in GitHub Desktop.
Save yuriitaran/84aee2faf3b514458f2656f16d659987 to your computer and use it in GitHub Desktop.
// Show post type Singular Label on singular post page:
$post = get_queried_object();
$postType = get_post_type_object(get_post_type($post));
if ($postType) {
echo esc_html($postType->labels->singular_name);
}
// Show post type Singular Label in the loop:
$postType = get_post_type_object(get_post_type());
if ($postType) {
echo esc_html($postType->labels->singular_name);
}
// Show post type Singular Label above the top of 'while':
$postType = get_post_type_object( 'photogallery' );
// >> These two usually contain the post type name in plural.
// >> They may differ though.
echo $postType->label;
echo $postType->labels->name;
// >> This one holds the post type name in singular.
echo $postType->labels->singular_name;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment