在Header.php之外修改WordPress页面标题

在Header.php之外修改WordPress页面标题,wordpress,Wordpress,有没有办法在header.php文件之外以编程方式指定页面标题 在我的一个页面模板文件中,我希望根据自定义字段中的值动态分配页面标题。这可能吗?下面是我在header.php中用来动态设置标题的一些代码。您可以使用类似的方法来获取自定义字段值 if (is_single() && have_posts()) { the_post(); echo "OKC ThunderCast: ".get_the_title(); rewind_posts(); //needed

有没有办法在header.php文件之外以编程方式指定页面标题


在我的一个页面模板文件中,我希望根据自定义字段中的值动态分配页面标题。这可能吗?

下面是我在header.php中用来动态设置标题的一些代码。您可以使用类似的方法来获取自定义字段值

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');
}

我能够使用过滤器挂钩为wp_title分配一个值:

function assignPageTitle(){
  return "Title goes here";
}
add_filter('wp_title', 'assignPageTitle');

这仍然在header.php中使用代码。我想尝试在header.php文件之外执行此操作。这可能吗?您可以编写一些动态JavaScript来设置标题(document.title=“x”),但谷歌或任何不执行JavaScript的客户机都无法获取该标题。是的,我真的希望facebook和其他搜索引擎能够获取该标题。