首页 > 解决方案 > URL 字段在锚点中未正确显示

问题描述

我遇到了一个非常有趣的问题。我正在为我的客户开发一个网站,并且使用高级自定义字段(没有 wordpress)遇到了这个问题。我已经为他们的奖励计划站点添加了一个新的自定义字段,但我无法让 url 字段正确工作。我已将代码添加到它需要的模板 php 文件中,目前它看起来像这样。

    <div class="row">
        <?php $ficvalue = get_field('free-icecream-url');
            if ($ficvalue) {
                $ficurl = esc_url($ficvalue);
            }?>
        <h3 class="heading" style="text-align: center;"><?php the_field('free-icecream-header'); ?></h3>
        <a href"<?php echo $ficurl; ?>" class="btn btn-primary" style="max-width: 15em;"><?php the_field('free-icecream-btn'); ?></a>
    </div>

当我将 url 放入页面编辑器后端的自定义 url 字段时,它没有正确显示在锚点中。如果我将此行添加到页面,它会在页面本身上正确显示 url:

    <?php echo get_field('free-icecream-url'); ?>

这将在插入自定义字段时显示 url,但是像这样将其添加到锚点的 href 中会提供不同的结果。

    <a href="<?php echo get_field('free-icecream-url'); ?>" class="btn btn-primary" style="max-width: 15em;"><?php the_field('free-icecream-btn'); ?></a>

    <!-- results as the following in chromes inspect -->
    <!-- https: www.rococoicecream.com rococo-rewards
         Instead of https://www.rococoicecream.com/rococorewards -->

我尝试使用 esc_url() 和 esc_html() 无济于事。并且在使用 the_field() 时会产生相同的结果。我究竟做错了什么?

标签: wordpresscustom-fields

解决方案


我在这里的问题的答案在发布后不久就得到了回答。我更新了原始问题,但我也会把它放在这里。我发现我遇到的问题是我在按钮的锚点中的 href 之后错过了一个 = 。发现这一点后,它就像一个魅力。


推荐阅读