admin管理员组文章数量:1291813
I'm using advanced custom fields to add a few fields to my posts. I want to prepend one of these fields to the content. I think I can do this using filters in wp, but I'm getting an odd result.
My filter to prepend a link to the content.
function add_fields_to_content($content)
{
$acf_library_url = the_field('acf_library_url');
$linkDisplay = '<a href="' . $acf_library_url . '">Link</a>';
return $linkDisplay .= $content;
}
add_filter('the_content', 'add_fields_to_content');
When the above filter runs I'd expect it to prepend a link to my content. For example
<a href="linktoexternalsite">Link</a>
... the rest of the content.
Instead, the url is appearing outside of the <a>
element and for some reason the URL of the posts is placed inside the href attribute. I think I'm misunderstanding something about how filters work in WP...
I'm using advanced custom fields to add a few fields to my posts. I want to prepend one of these fields to the content. I think I can do this using filters in wp, but I'm getting an odd result.
My filter to prepend a link to the content.
function add_fields_to_content($content)
{
$acf_library_url = the_field('acf_library_url');
$linkDisplay = '<a href="' . $acf_library_url . '">Link</a>';
return $linkDisplay .= $content;
}
add_filter('the_content', 'add_fields_to_content');
When the above filter runs I'd expect it to prepend a link to my content. For example
<a href="linktoexternalsite">Link</a>
... the rest of the content.
Instead, the url is appearing outside of the <a>
element and for some reason the URL of the posts is placed inside the href attribute. I think I'm misunderstanding something about how filters work in WP...
1 Answer
Reset to default 1The problem not it wp hook,
the_field() displays the value of a specific field, so you need to use get_field() instead, which returns a value.
本文标签: filtersUsing addfilter to prepend contentresult is out of order
版权声明:本文标题:filters - Using add_filter to prepend content, result is out of order 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741540955a2384316.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论