Depending on the way your theme uses the_title
, hooking into the the_title
filter may or may not hide the title h1. What theme are you using?
The the_title
filter passes two arguments: the title (string) and the post ID. Therefore, treating the title as an array (it looks like you’re assuming $title
is an array of post data, trying to set $title['post_title']
. To have the_title
return an empty string if the custom field “hide_title” is not empty, the following would suffice:
add_filter( 'the_title', 'wpse145940_hide_hidden_title', 10, 2 );
function wpse145940_hide_hidden_title( $title, $postid ) {
if ( get_post_meta( $postid, 'hide_title', true ) ) {
$title="";
}
return $title;
}