警告:第 62 行 ..../footer.php 中未定义数组键“logo_max_width”>

问题描述 投票:0回答:1
advanced-custom-fields
1个回答
0
投票

您可以通过使用

isset()
检查数组键是否存在来解决此问题。我们正在访问
$footer['logo_max_width']
,您应该使用
isset()
函数 () 检查它是否存在。

<a href="<?php echo home_url(); ?>" class="home-link" 
    <?php if (isset($footer['logo_max_width'])) { 
            echo 'style="max-width:' . esc_attr($footer['logo_max_width']) . 'px;"'; 
        }
    ?>>
    <img src="<?php echo esc_url($footer['logo']['url']); ?>" alt="<?php echo esc_attr($footer['logo']['alt']); ?>" />
</a>

如果您想避免丢失键,可以设置默认值如果 ACF 未提供

logo_max_width
字段值

$maxWidth = isset($footer['logo_max_width']) ? esc_attr($footer['logo_max_width']) : 200; // Default to 200px if not set

请尝试此解决方案来解决问题

© www.soinside.com 2019 - 2024. All rights reserved.