How do i display the post type title?

Hi i was wondering if there is a way that i can display the custom post type title.

For example:

Read More

I have a custom post type entitled “Pretty Little Liars” and it also shows on the homepage, but how do i get the POST TYPE title, not the title of the post to show up like a category.

For example:

Plublished in: Pretty Little Liars

is this possible?

Also i want it to link to the post type page

Related posts

Leave a Reply

2 comments

  1. 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().