wordpress - 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() 时会产生相同的结果。我究竟做错了什么?
解决方案
我在这里的问题的答案在发布后不久就得到了回答。我更新了原始问题,但我也会把它放在这里。我发现我遇到的问题是我在按钮的锚点中的 href 之后错过了一个 = 。发现这一点后,它就像一个魅力。
推荐阅读
- python - 如何在 boto3 中为 AWS EC2 实例设置标签
- amazon-web-services - 在模板中启用默认加密的无服务器 S3 存储桶事件
- sql - 动态列名映射到另一个表以复制数据
- html - 如何在 Twitter Bootstrap 部分的背景上叠加图像
- javascript - 将两页视图更改为单页AngularJS
- python - 如何检查输入的任何部分是否是python列表的一部分
- hyperledger-fabric - Hyperledger Fabric 中每个块的块大小和事务
- android - Android 创建自定义键盘
- c# - 运行 UWP 应用程序(C#)时没有显示 StackPanel
- wordpress - 在由 wordpress 进行身份验证之前,首先验证 wordpress 登录凭据到 api