0

我正在尝试在我的 functions.php 文件的 about 页面上删除 h1 标题。

这是我的代码:

function remove_about_page_title()
{
    if (is_page('about')) {
        remove_action('storefront_page', 'storefront_page_header', 10);
    }
}
add_action('init', 'remove_about_page_title');

如果我在上面进行 var 转储,is_page('about')那么false即使它是关于页面,我也会得到。

如果我将add_action()函数更改为将remove_about_page_title()函数从 init 运行到storefront_pagethenis_page()打印 true 但 remove_action 函数不再起作用。

这是因为超出了范围链吗?

有没有办法在functions.php没有 CSS 和#ids 的情况下删除文件内的页眉?

4

2 回答 2

1

我会在您的functions.php 文件中创建一个数组,其中包含您要隐藏标题的页面名称。

函数.php

$noTitle = array("page1", "page2");

头文件.php

if(in_array($title, $noTitle)){
    //no title
}
else{
    //title
}

At least I think you can do it this way. You may want to check when functions.php gets loaded. If it is not loaded by now, you may have to make another php file and load it manually at the top of the header.php file.

于 2018-03-22T12:23:38.147 回答
1

You have to use is_page('pageId') instead of is_page('about');

于 2018-03-22T12:30:11.180 回答