I believe checking in_the_loop
will work for the main query:
function custom_title( $title ) {
global $post, $wp_query;$post;
$text = 'Extra text: ';
if ( get_post_type( $post->ID ) == 'custom_post_type' && $wp_query->in_the_loopin_the_loop() ){
return $text . $title;
}
else {
return $title;
}
}
add_filter( 'the_title', array($this, 'custom_title' ) );