• Resolved nick1999

    (@nick1999)


    Hi CPTUI support team,

    Do you have any shortcode to display only the title of the custom post type. Or could you guide me on how to achieve this?

    I am waiting for your reply,
    Thanks

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Are you trying to display the current post’s title dynamically in some way? or perhaps inside its own post content? Or somewhere else?

    Not quite sure on the usecase here, which would help me provide a better answer.

    Thread Starter nick1999

    (@nick1999)

    I created a post-type Movie and I have published some posts on it now I want to show the Custom post type title (i mean I want to show the word “movies”) in the posts of Movie only.

    I am waiting for your reply,
    Thanks.

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Something like this should work

    add_shortcode( 'post_type_title', 'nick1999_post_type_title' );
    function nick1999_post_type_title( $atts ) {
    	$atts = shortcode_atts( [
    		'post_type' => '',
    	], $atts );
    
    	if ( empty( $atts['post_type'] ) ) {
    		return '';
    	}
    
    	$obj = get_post_type_object( $atts['post_type'] );
    
    	return $obj->label;
    }
    

    Usage example: [post_type_title post_type="movies"]

    Would return: Movies if the plural label is as such. Editing the plural label later would affect all of the instances of the shortcode.

    Thread Starter nick1999

    (@nick1999)

    Hi,
    Thanks for your support,
    my issue has been solved,
    you can mark this thread as resolved,
    Thank you, Sir.

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Glad we could help. Let us know if anything else comes up.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Shortcode for custom post type title’ is closed to new replies.