最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

advanced custom fields - Override not echoing my string or dom element

programmeradmin8浏览0评论

Hi all I'm kind of new to WordPress. I have created an override for WooCommerce and I'm trying to echo a DOM element with an Advanced Custom Field in it.

I've used this code.

<?php
if (the_field('price_per_unit'))
{
    echo '<span class="unit-price">Price per unit: ' .  the_field('price_per_unit') . '</span>';
}
echo '<p>Test</p>';
?>

The custom field arrives, so I know I'm in the right file, but the <p> does not and the word "Test" does not.

Can anyone explain why this happens and how I can get my DOM elements to appear?

I thought it might be some kind of a sanitiser to I tried echoing just the word without any HTML but that also didn't work.

Many thanks

Hi all I'm kind of new to WordPress. I have created an override for WooCommerce and I'm trying to echo a DOM element with an Advanced Custom Field in it.

I've used this code.

<?php
if (the_field('price_per_unit'))
{
    echo '<span class="unit-price">Price per unit: ' .  the_field('price_per_unit') . '</span>';
}
echo '<p>Test</p>';
?>

The custom field arrives, so I know I'm in the right file, but the <p> does not and the word "Test" does not.

Can anyone explain why this happens and how I can get my DOM elements to appear?

I thought it might be some kind of a sanitiser to I tried echoing just the word without any HTML but that also didn't work.

Many thanks

Share Improve this question asked Jul 30, 2020 at 13:46 EoinEoin 1156 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

Thats odd - it works ok here if I simulate this as a text field but other field types may cause a problem.

Try replacing 'the_field()' with 'get_field()' in your code.

If that doesn't work - how is your field setup? Text, Number, Date etc...

发布评论

评论列表(0)

  1. 暂无评论