How to display CPT’s singular_label in Bricks

Looking to get and output a post type’s singular label in Bricks on single CPT pages?

Define a custom function by adding the following in your child theme’s functions.php or a code snippets plugin:

function bl_get_post_type_singular_label() {
	$post_type_object = get_post_type_object( get_post_type() );
	return $post_type_object->labels->singular_name;

and then replace a Heading/Basic Text element’s default text with:


where needed.

Welcome to {echo:bl_get_post_type_singular_label}-Post

for example, in a Bricks template that has been set to apply to either CPTs, would show

Welcome to Testimonial-Post

when viewing a testimonial custom post type’s singular page like https://bricks.local/testimonial/frances-harper/.


Welcome to Event-Post

when viewing a event CPT’s singular page like https://bricks.local/event/t20-cricket-world-cup/.


Instant access to 390+ Bricks code tutorials with BricksLabs Pro

1 comment

Leave your comment