Your call to get_post_type()
needs to be passed the $post
object, which you don’t globalize until later. Try globalizing the $post
object earlier. Also, try using foo != bar
instead of ! foo == bar
:
function change_title ( $title ) {
global $post;
if ( 'events' == get_post_type( $post ) ) {
$custom = ( get_post_custom( $post->ID ) ? get_post_custom( $post->ID ) : false );
$custom_title = ( isset( $custom['_location'][0] ) ? $custom['_location'][0] : '(No Title)' );
return $custom_title;
} else {
return $title;
}
}
add_filter( 'the_title', 'change_title' );
Edit
Also, to ease of troubleshooting, I would recommend writing your conditional in the affirmative with respect to your custom post type, i.e. if ( 'events' == get_post_type( $post ) )
, rather than if ( 'events' != get_post_type( $post ) )
. The former will only ever return true for your post type; the latter will return true always except for your post type.