Modify WordPress Page Title Outside of Header.php
Is there a way to programmatically assign the page title outside of the header.php file?
In one of my page template files, I would like to dynamically assign the pa开发者_Go百科ge title based on a value in a custom field. Is this possible?
I was able to use a filter hook to assign a value to wp_title:
function assignPageTitle(){
return "Title goes here";
}
add_filter('wp_title', 'assignPageTitle');
Here is some code I use in header.php to set the title dynamically. You could use something similar to get your custom field value.
if (is_single() && have_posts()) {
the_post();
echo "OKC ThunderCast: ".get_the_title();
rewind_posts(); //needed so that the call to The Loop on single.php will find the posts
} else {
bloginfo('name');
}
精彩评论