Support

Account

Home Forums Front-end Issues unexpected commas

Helping

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)

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.