0

When I need to add a custom page to a WordPress-based site, I always load the theme's header first:

<?php
  require('../wp-blog-header.php');
  include('../wp-content/themes/mytheme/header.php');
?>

Unfortunately, then every custom page gets the same title (the blog's name) due to this code in header.php:

<head>
<title><?php if(is_home()) { bloginfo('name');} else { bloginfo('name'); echo ' | '; the_title(); } ?></title>

What would be the best way to change this page title?

  • Is there a WordPress method to call before loading the header that will change the_title()'s return value?
  • Should I change the header.php call, so it will check if there is a previously defined custom value for my title?
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Felipe Hoffa
  • 54,922
  • 16
  • 151
  • 325

2 Answers2

3

To answer your questions,

  1. Yes, there is; you might want to look at WordPress Hooks and Filters. A good list of available hooks and filters for WordPress 3.0 is here.
  2. I'd probably just use the is_page() WordPress function. You can use it as is to check whether WordPress is rendering a custom page, or supply a parameter (an id, a page title, etc.) to check for more specific ones.
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Richard Neil Ilagan
  • 14,627
  • 5
  • 48
  • 66
1

Actually you can look at your header code like this:

<?php
    if (is_home()) {
         bloginfo('name');
   } else {
         bloginfo('name'); echo ' | '; the_title();
    } ?>

Translating: if (it is your home) then print the blog's name. Else, print the blog's name, a | bar and the page/post title.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Beto Frega
  • 956
  • 6
  • 21