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 🙂

2 Answers
2

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.

Leave a Reply

Your email address will not be published. Required fields are marked *