You've almost got it!
Here's your original code:
add_filter( 'the_title', 'remove_page_title' );
function remove_page_title() {
if(is_page('138')) {
}
return '';
}
What it's doing is adding a filter on the_title
that doesn't accept any parameters. That's your first mistake. The the_title
filter actually takes two parameters - the page/post title and the page/post id. So first, let's rewrite our hook:
add_filter( 'the_title', 'remove_page_title', 10, 2 );
function remove_page_title( $title, $id ) {
}
This assigns our filter with a priority of 10 and lets us accept both parameters sent in by the filter. Then we specify the parameters our function accepts.
Inside the function, we want to check if we're on the right page. If we are, return ''
, if we aren't return the title:
if( '138' == $id ) return '';
return $title;
Your original function was always returning ''
when the filter ran. That's why you were getting a blank title on every page, not just the page you wanted.
Our full code
So your full filter, rewritten to accept parameters and use the proper logic:
add_filter( 'the_title', 'remove_page_title', 10, 2 );
function remove_page_title( $title, $id ) {
if( '138' == $id ) return '';
return $title;
}
front-page.php
template and remove the title?