Php WordPress播客模板:在获取标题之前覆盖标题()
我有一个使用模板的pods页面,它工作得很好。但我只需要用一个包含值的pods字段覆盖title标记:Php WordPress播客模板:在获取标题之前覆盖标题(),php,wordpress,Php,Wordpress,我有一个使用模板的pods页面,它工作得很好。但我只需要用一个包含值的pods字段覆盖title标记: $parcours = pods('parcours', pods_v_sanitized(3, 'url')); $seo_title = $parcours->field('seo_title'); // Supposed override function custom_page_title($seo_title) { retu
$parcours = pods('parcours', pods_v_sanitized(3, 'url'));
$seo_title = $parcours->field('seo_title');
// Supposed override
function custom_page_title($seo_title) {
return $seo_title;
}
add_filter('pre_get_document_title', 'custom_page_title', 999, 1);
get_header();
?>
标题不显示在页面上(无替代)。当然,我确保$seo\u title
确实有一个值
我是否遗漏了一些内容,或者这样做是不可行的?您试图使用函数中的
$seo\u title
变量作为一个变量
如果您这样使用代码,代码将正常工作:
$parcours = pods('parcours', pods_v_sanitized(3, 'url'));
global $seo_title;
$seo_title = $parcours->field('seo_title');
// Supposed override
function custom_page_title() {
global $seo_title;
return $seo_title;
}
add_filter('pre_get_document_title', 'custom_page_title', 999);
get_header(); ?>
带有行global$seo\u标题代码>,我们正在调用函数外的变量:
$seo_title = $parcours->field('seo_title');
您试图将函数中的$seo\u title
变量用作
如果您这样使用代码,代码将正常工作:
$parcours = pods('parcours', pods_v_sanitized(3, 'url'));
global $seo_title;
$seo_title = $parcours->field('seo_title');
// Supposed override
function custom_page_title() {
global $seo_title;
return $seo_title;
}
add_filter('pre_get_document_title', 'custom_page_title', 999);
get_header(); ?>
带有行global$seo\u标题代码>,我们正在调用函数外的变量:
$seo_title = $parcours->field('seo_title');
谢谢,是的,关于范围你是对的,但不幸的是标题元没有改变。我尝试了代码,它工作了。您的问题在于前两行。添加var\u转储($seo\u title)代码>在这一行之后$seo_title=$parcours->field('seo_title')代码>你会得到emty string,null,false或者类似的东西谢谢是的,我在变量名中有一个输入错误,但是现在变量作为字符串存在(例如string(42)“Randonnée dans le Sahara marocain-Maroc”),但是标题没有被覆盖,我使用的是正确的钩子吗?确实!伟大的txs!非常感谢。999是它真正让我工作的地方。谢谢,是的,你对范围的看法是正确的,但不幸的是标题meta没有更改。我尝试了代码,它工作了。您的问题在于前两行。添加var\u转储($seo\u title)代码>在这一行之后$seo_title=$parcours->field('seo_title')代码>你会得到emty string,null,false或者类似的东西谢谢是的,我在变量名中有一个输入错误,但是现在变量作为字符串存在(例如string(42)“Randonnée dans le Sahara marocain-Maroc”),但是标题没有被覆盖,我使用的是正确的钩子吗?确实!伟大的txs!非常感谢。999是它真正让我工作的地方。