Showing the post type name in result title or content

Displaying post type name in the live results title or content field

What is this, and where do I put this custom code?

Post type name in title

add_filter( 'asp_results', 'asp_show_the_post_type_title', 10, 1 );
function asp_show_the_post_type_title( $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->title = $post_type_obj->labels->singular_name . ' - ' . $r->title;
		}
  }

  return $results;
}

Post type name in content

add_filter( 'asp_results', 'asp_show_the_post_type_content', 10, 1 );
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 = $post_type_obj->labels->singular_name . ' - ' . $r->content;
		}
  }

  return $results;
}

Last updated