How to correctly get post type in a the_title filter

You can exclude menus by testing the post id :

add_filter( 'the_title', 'add_cpt_prefix' );

function add_cpt_prefix( $title ) {
    global $id, $post;
    if ( $id && $post && $post->post_type == 'press' ) {
        $title="<span>Press:</span> " . $title;
    }
    return $title;
}

Leave a Comment