This website uses cookies to personalize your experience. By using this website you agree to our cookie policy.

Reply To: Display names of post types

#49099
Ernest MarcinkoErnest Marcinko
Keymaster

Hi Christian,

Sure! With a tiny bit of modification it’s possible to add a CSS class:

function asp_show_the_post_type_content( $results ) {
	foreach ($results as $k=>&$r) {
		if ( isset($r->post_type) ) {
			// Modify the post title
			$post_type_obj = get_post_type_object( $r->post_type );
			$r->content = "<div class='$r->post_type'>" . $post_type_obj->labels->singular_name . '</div> - ' . $r->content;
		}
	}

	return $results;
}

With this, the post type is wrapped in a div with the post type class name, which you can reference by:

.asp_r .post_type_slug {

}