0

with this function I change the title of my posts in the posts type 'alternatives'. My problem is that Wordpress changes all my titles now. Does anyone know how I can set this for the specific custom post type only?

// Change alternatives title
function alternatives_title( $title, $post_id ) {
    if( get_post_type( $post_id ) == 'alternatives' ) {
        $title = $title . ' alternative';   
    } 
    return $title;
}
add_filter( 'the_title', 'alternatives_title' );
add_filter( 'get_the_title', 'alternatives_title' );
0

You need to set the number of arguments your filter accepts:

add_filter( 'the_title', 'alternatives_title', 10 /* Priority */, 2 /* Arguments */ );

And you only need to use the_title (there is no get_the_title filter).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.