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.

Hi can anyone help with the below, please?

I want to be able to change the contents of my HTML <title> tag only, so need to write an if / else statement.

I'm getting myself a bit muddled as my PHP isn't great... but basically something along the lines of the below but combined...

<?php if ( ! is_page_template('boatDetails.php') ) { ?>
<title><?php bloginfo('name'); ?><?php wp_title('|'); ?></title>
<?php } ?>
<?php if ( is_page_template('boatDetails.php') ) { ?>
<title>I'm the boat details page</title>
<?php } ?>

Thanks :)

share|improve this question
    
For a more precise answer, can we see the contents of boatDetails.php? –  Chip Bennett Aug 20 '12 at 16:12
    
Hiya - unfortunately it's on client protected IP filtered server as the site is in development. I'm not sure whether it's necessary though is it? I can get the 'I'm the boat details page' title to appear on that page - and the other title tag to render on all other pages, I just want to know how to combine the two statements into an if/else... –  V Neal Aug 20 '12 at 16:15
    
I think it can be answered generally (see my answer below), but you should always include relevant code - or, as appears is the case here, at least say that you're adding the relevant code from header.php. It just helps us understand/answer the question better. –  Chip Bennett Aug 20 '12 at 16:19
    
Ok sorry - yes I was attempting to write it in header.php. The below solution does work - thank you - although I may need to add it to my boatDetails.php template itself as the boat info is fed via xml and therefore needs to be dynamically generated from the content pulled in. Sorry - should have mentioned that to begin with. –  V Neal Aug 20 '12 at 16:31
1  
Can you clarify your question with this information, so that it can be addressed? Please explain what you're doing, where the dynamically generated content is coming from, and what specific data you want to use in the document title. –  Chip Bennett Aug 20 '12 at 16:38
add comment

1 Answer 1

up vote 1 down vote accepted

I think you will want to use the wp_title filter. Add the following to functions.php:

function wpse62415_filter_wp_title( $title ) {
    // Return a custom document title for
    // the boat details custom page template
    if ( is_page_template( 'boatDetails.php' ) ) {
        return 'I\'m the boat details page';
    }
    // Otherwise, don't modify the document title
    return $title;
}
add_filter( 'wp_title', 'wpse62415_filter_wp_title' );

Make no other changes anywhere, including in header.php.

share|improve this answer
add comment

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.