问题
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,
回答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.
Is it printing ONLY the blog's name on custom pages or is it performing correctly?
回答2:
To answer your questions,
- Yes there is; you might want to look at WP Hooks and Filters. A good list of available hooks and filters for WP 3.0 is here.
- I'd probably just use the
is_page()
WP function. You can use it as is to check whether WP is rendering a custom page, or supply a parameter (an id, a page title, etc) to check for more specific ones.
来源:https://stackoverflow.com/questions/3570674/changing-the-title-of-a-custom-wordpress-integrated-page