Skip to content
Advertisement

changing the title of a custom WordPress integrated page

When I need to add a custom page to 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?

Thanks,

Advertisement

Answer

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.

Is it printing ONLY the blog’s name on custom pages or is it performing correctly?

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement