将高级自定义字段显示为超链接


Showing advanced custom field as hyperlink

我是PHP新手,无法理解一件简单的事情:

我需要在Woordpress上输出"高级自定义字段"作为超链接。以下是我正在使用的代码,但我不确定如何正确地将设置为_field('my-customerlink')成为超链接。它目前正在显示输出,但没有像我希望的那样将其显示为包装链接

printf( '<div class="pdf-cover"><a href="' . the_field('my-custom-link') .'" title="%s">%s</a></div>', the_title_attribute( 'echo=0' ), $img );

提前Thx!

我不知道Wordpress上有任何函数the_field,所以这意味着你在使用插件。

然而,大多数与wordpress和wp相关的函数都有一个回显版本(在本例中为the_field)和一个返回版本(应该是get_the_fieldget_field

所以,请尝试

printf( '<div class="pdf-cover"><a href="' . get_the_field('my-custom-link') .'" title="%s">%s</a></div>', the_title_attribute( 'echo=0' ), $img );

printf( '<div class="pdf-cover"><a href="' . get_field('my-custom-link') .'" title="%s">%s</a></div>', the_title_attribute( 'echo=0' ), $img );