特定文本区域字段类型的 ACF 自动超链接


ACF Auto hyper link for specific Textarea field type

我在主题函数中添加了下面的代码

add_filter( 'the_content', 'make_clickable', 12 );

这使得"the_content"中的所有文本 url 自动超链接。但不是我的高级自定义字段之一。

再次,我通过在主题函数中添加它并使用 acf 过滤器来为我的自定义字段尝试了这个

add_filter('load_field/name=downloadable_links', 'my_acf_load_field', 'make_clickable', 12);

但这只会使我的自定义字段 url 内容不可见,而不是超链接。

这是我的自定义字段downloadable_links。字段类型:文本区域。我也在用中继器。我在每个字段中都有几个链接,我希望它们都是自动超链接,而不是每次都手动进行。

这是我的自定义字段前端输出代码。

<div><?php echo do_shortcode("[acf field='file_sharing_name']"); ?><? $folios = get_field('game_download'); if($folios){foreach( $folios as $f ){?><div class="wrap"><div class="file-zone-title"><? if($f){ ?><span><?= $f['file_sharing_name']?></span><? } ?></div><div class="file-download-links"><?= $f['downloadable_links']?></div><div class="clear"></div></div><?}} ?><div class="clear"></div></div>

如果有人能建议我如何让它工作,那将非常友善。因为我无法使其与上述信息一起工作。第一次在这里征求建议。因此,如果我的请求中有任何错误,我很抱歉。提前谢谢。

我能够自己并在其他主题的帮助下修复它。 :)在做了更多的研究之后。

我在这里遵循了以下提示:

https://wordpress.stackexchange.com/questions/103957/how-to-explode-a-textarea-field-and-echo-each-line-separately-wrapped-with-html

并将我的自定义字段的函数输出代码修改为此,它可以像我想要的那样与超链接一起工作。

    $lines = explode("'n", get_field('downloadable_links')); // or use PHP PHP_EOL constant
if ( !empty($lines) ) {
  echo '<ul>';
  foreach ( $lines as $line) {
    echo '<li>'. '<a href=' . $line . '>' . trim( $line ) . '</a>' . '</li>';
  }
  echo '</ul>';
}

祝你好运 - 如果其他人需要这个。 :)