Telefon link fra et ACF felt

Den gode Husum har lavet et fix til telefon links via ACF felter ( fx. til en dynamisk medarbejder side )

  1. Du skal bruge pluginnet “Code Snippets” til koden, downloader derfor denne. (Kan hentes gratis)
  2. Du opretter et normalt ACF tekst felt til de telefonnumre.
  3. På knappen / ikonlisten mm. tilføj Shortcode som dynamisk tag i URL feltet
  4. Tilføj denne shortcode: [get_acf_value meta_field=”telefonnummer” prefix=”tel:+45 “]
  5. Done!

Indsæt i pluginnet "Snippets"

function custom_acf_shortcode($atts) {
    // Define the default attributes
    $atts = shortcode_atts(
        array(
            'meta_field' => '', // ACF field key
            'prefix'     => '', // Prefix to add before the value
        ), 
        $atts, 
        'acf_value'
    );

    // Get the ACF field value
    $acf_value = get_field($atts['meta_field']);

    // Check if the field exists and return the value with the prefix
    if ($acf_value) {
        return $atts['prefix'] . $acf_value;
    } else {
        return ''; // Return empty if no value is found
    }
}

// Register the shortcode
add_shortcode('get_acf_value', 'custom_acf_shortcode');