Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php WordPress播客模板:在获取标题之前覆盖标题()_Php_Wordpress - Fatal编程技术网

Php WordPress播客模板:在获取标题之前覆盖标题()

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

我有一个使用模板的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) {

        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是它真正让我工作的地方。