How do i display the post type title?

You can write a general template tag for this task.

function wpse60306_get_post_type( $echo = true )
{
    static $post_types, $labels="";

    // Get all post type *names*, that are shown in the admin menu
    empty( $post_types ) AND $post_types = get_post_types( 
        array( 
            'show_in_menu' => true,
            '_builtin'     => false,
        ),
        'objects'
    );

    empty( $labels ) AND $labels = wp_list_pluck( $post_types, 'labels' );
    $names = wp_list_pluck( $labels, 'singular_name' );
    $name = $names[ get_post_type() ];

    // return or print?
    return $echo ? print $name : $name;
}

Explanation

We got two variables declared as static, so we don’t have to redo the task, if you’re for example using it inside a loop that shows posts from different post types.

You also got an argument ((bool) true/false) to switch if you just want to return or right print the name.

This function doesn’t work for built in post types (assuming you don’t need it). If you need it for built in post types too, then just remove the _builtin argument from the function inside ↑ get_post_types().

Leave a Comment