By default, when you add URL to a page using ACF Field Picker, it’s displaying link as URL. It is possible to use ACF field’s label as a title for URL. To do so, you need to add a custom filter function to your functions.php file under child theme folder.


// add_filter( 'vc_acf_field_picker_render_field_type_url', 'vc_acf_field_picker_render_filter_url_with_title', 15, 3 );
// add_filter( 'vc_acf_field_picker_render_field_key_field_58c676aa18d82', 'vc_acf_field_picker_render_filter_url_with_title', 15, 3 );
add_filter( 'vc_acf_field_picker_render_field_name_url', 'vc_acf_field_picker_render_filter_url_with_title', 15, 3 );
function vc_acf_field_picker_render_filter_url_with_title( $value, $field_object, $post_id ) {
  $label = is_array( $field_object ) && isset( $field_object[ 'label' ] ) ? $field_object[ 'label' ] : '';

  if ( $label ) {
    $value = sprintf( '<a href="%s" title="%s">%s</a>', $field_object[ 'value' ], $label, $label );
  }

  return $value;
}

Note: ACF Field Picker allows targeting filters based on ACF Field type, name or key. The corresponding filter formats are:

  • Field type: “vc_acf_field_picker_render_field_type_{acf_field_type}”
  • Field name: “vc_acf_field_picker_render_field_name_{acf_field_name}”
  • Field key: “vc_acf_field_picker_render_field_key_{acf_field_key}”

In this example targeting by type and key are commented out and used just targeting by field name. You need to do two things:

  1. Choose your targeting method: type, name or key
  2. Replace the type, name or key in the filter with the right value as per your ACF Field settings

Don't have WP ACF-VC Bridge yet?

Combine the powers of two giants

Get a must have plugin for modern WordPress website today!

0
Comments

Leave a Reply

Your email address will not be published. Required fields are marked *