我知道这个问题之前已被问过几千次,但我尝试了很多这些解决方案却没有取得任何成功.
原文链接:https://www.f2er.com/php/136608.htmladd_filter('the_title','callback_to_set_the_title'); add_filter('wp_title','callback_to_set_the_title'); global $title; $title = 'My Custom Title'; add_filter( 'pre_get_document_title','callback_to_set_the_title' ); add_filter( 'document_title_parts','callback_to_set_the_title' );
方案是我有一个工作列表页面的自定义模板.这个页面有重写的URL重写domain.com/about/careers/search/job?slug=whatever到domain.com/about/careers/search/job/whatever- slug用于从Redis检索一个条目包含工作列表的所有信息,包括我想要使用的标题.
这是我如何重写URL(来自functions.PHP):
function job_listing_url_rewrite() { global $wp_rewrite; add_rewrite_tag('%slug%','([^&]+)'); add_rewrite_rule('^about/careers/search/job/([a-zA-Z0-9-_]+)/?','index.PHP?page_id=6633&slug=$matches[1]','top'); $wp_rewrite->flush_rules(true); } add_action('init','job_listing_url_rewrite',10,0);