0

I would want to show some HTML code in my WordPress page. So in my child theme functions.php, I have written an action like this one:

add_action('wp', function() {
    if(is_admin()) {
        return;
    }
    
    $html = '<div class="home_immodvisor">';    

    echo $html; 
});

However, a warning is displayed when I go to the back-office (admin) login page:

Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/wp-content/themes/hello-elementor-child/functions.php:88) in /var/www/html/wp-includes/pluggable.php on line 1296

Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/wp-content/themes/hello-elementor-child/functions.php:88) in /var/www/html/wp-includes/pluggable.php on line 1299

My question is: is it the good action to hook? Or should I use another one than wp?

4

3 回答 3

1

据我了解,wordpress 在 wp 之后发送标题,所以这是错误的地方,因为您之前无法回显。

于 2020-09-08T09:13:13.973 回答
0

没有用于在主题中插入 html 的标准化钩子/操作。每个主题都可以以不同的方式处理这个问题,有些甚至可能没有钩子。

但是如果你必须wp_head钩子可以工作,但它不会是有效的 HTML。

最好的办法是检查你的 thema 的文档。或者制作一个儿童主题并调整模板)你需要

于 2020-09-08T09:41:31.453 回答
-2

警告:无法修改标头信息 - 标头已由

要解决此问题,请在主题 function.php 文件中添加以下代码

ob_start();

它将消除您的错误。

于 2020-09-08T09:29:49.460 回答