Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'd like to remove the post title from my static frontpage. Just that page. I've created a child theme from a free Press75 theme. So I'd like to make this change in my child theme's function.php.

I used this code but it removes the title from all pages, posts and my navigation:

add_filter( 'the_title', 'remove_page_title' );

function remove_page_title() {
    if(is_page('138')) {
    }
    return '';
}

I thought it would just remove the title from the page with ID 138. What am I doing wrong?

Thanks!

share|improve this question
    
Create a front-page.php template and remove the title? –  t31os Mar 29 '11 at 22:59
    
Stumbled upon this as I am having the exact same problem. Tried the Kaiser-Chip approach which worked fine - except it also removed all menu items + all post titles in the sidebar widget. Also, although it removed the title of the page, the styling of the title remained - including some padding and a border-bottom. Is there another solution? –  user4317 Mar 30 '11 at 10:32
    
This was the easiest solution. But it just seems like overkill to create a template just to remove the title. I'm able to do this in the functions.php when I use the Hybrid Framework, just by using one of Justin's hooks. –  Intrepid Realist Mar 31 '11 at 21:10
    
@Anders Could you delete this answer and add it as a new question. –  Chris_O Apr 6 '11 at 8:56

4 Answers 4

wrap your add_filter function call around a conditional tag and use the builtin return false function:

if ( is_page('138') )
{
      add_filter( 'the_title', '__return_false' );
}
share|improve this answer
1  
I like this suggestion, but wouldn't if ( ! is_front_page() ) be better to use than a hard-coded page ID, such as if ( is_page( '138' ) )? –  Chip Bennett Mar 29 '11 at 20:30
1  
@Chip Bennett - Surely better. But from reading the Q, the A fits well. IMO i think it's better to offer a solution that's as close as possible to the Q, even when there are lots of better solutions available. There's a saying where i come from: "The farmer doesn't eat what he doesn't know". –  kaiser Mar 29 '11 at 20:57
1  
But this was the original issue: " I'd like to remove the post title from my static frontpage. Just that page." In which case, I would definitely recommend the front-page.php template file solution. In any case, your answer got my vote. –  Chip Bennett Mar 30 '11 at 3:10
    
I add this code using page ID or is_front_page and nothing happens... –  Intrepid Realist Mar 31 '11 at 21:11
    
I'm not sure about the __return_false function. It could be named close to that. You could also write a small fn yourself that returns false and add it. Anyway, Chip's comment is the best solution. –  kaiser Apr 1 '11 at 2:04

One way for header.php:

<?php if (is_page('138')) { echo'
<style type="text/css" title="text/css">
yourpagetitleselector {display:none;}
</style>'
; ?>
share|improve this answer

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;
}
share|improve this answer

If I understand you correctly -- that you want to display no <title> for the front page -- you can use:

<title><?php if ( ! is_front_page() ) { the_title(); } ?></title>
share|improve this answer
1  
<title> !== the_title(); See: codex.wordpress.org/Function_Reference/the_title Further more this exactly what @Chip Bennett suggested as a comment to my Answer. –  kaiser Mar 29 '11 at 20:58
    
Sheesh. I answered before Chip posted his comment. I also clarified my answer by "if I understand you correctly," which clearly I did not. –  Ryan Mar 29 '11 at 21:12
    
@Ryan: Sorry if i did you wrong. I just compared the time and there were 2min difference. –  kaiser Mar 29 '11 at 22:18
1  
I do hope that answers, voting, reputation, etc. aren't terribly contentious here? I'm not really worried about them; what really matters is that people get help with solving their problems, yeah? –  Chip Bennett Mar 30 '11 at 3:15
1  
@kaiser: I appreciate that -- I was more upset at myself for not reading the question, which you correctly answered. It was a bit of a shock being a n00b on this site and getting downvoted but, as Chip says, it's about getting people their answers. :) –  Ryan Mar 30 '11 at 4:45

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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