Home › Forums › Front-end Issues › unexpected commas
Hi everobody,
A rookie around here
When Inserting my ACF type link in a Grid template of WPBakery the results on the website are just text, the generated HTML looks like this:
<div field_64f75f5789e38="" class="vc_gitem-acf field_64f75f5789e38">text, url, link, </div>
So I have created the following function to replace this generated HTML for a custom one:
function custom_format_acf($value, $post_id, $field) {
if ($field['name'] === 'download_webinars_button' && is_array($value)) {
$title = isset($value['title']) ? $value['title'] : '';
$url = isset($value['url']) ? $value['url'] : '';
$target = isset($value['target']) ? $value['target'] : '_self';
$output = '<div class="vc_btn3-container vc_btn3-inline sqz-custom-card">';
$output .= '<a class="vc_general vc_btn3 vc_btn3-size-md vc_btn3-shape-rounded vc_btn3-style-modern vc_btn3-color-grey" ';
$output .= 'href="' . esc_url($url) . '" title="' . esc_attr($title) . '" target="' . esc_attr($target) . '">';
$output .= esc_html($title);
$output .= '</a>';
$output .= '</div>';
$value = trim($output);
}
return $value;
}
add_filter('acf/format_value/type=link', 'custom_format_acf', 10, 3);
And it works correctly, but I find that the generated code looks like this:
<div field_64f75f5789e38="" class="vc_gitem-acf field_64f75f5789e38">
,
<div class="vc_btn3-container vc_btn3-inline"><a class="vc_general vc_btn3 vc_btn3-size-md vc_btn3-shape-rounded vc_btn3-style-modern vc_btn3-color-grey" href="#form" title="patata en" target="">patata en</a></div>
,
</div>
And although everything seems to work fine, I get 2 commas at the beginning and end of my html code that I can’t get rid of.
Any ideas?
is the return value of your link field set to “Link Array”? This will be required.
Then set the priority of your filter to > 10 (for example 20)
You must be logged in to reply to this topic.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.