Home › Forums › Bug Reports › field type link doesn't update › Reply To: field type link doesn't update
Maybe this might help someone, I’m attaching my configuration for a link-button. It offers variations for internal, external and on-page (anchor) links.
Also, this is a function to output a link:
function nij_output_link($atts, $class = '') {
if (!empty($atts)) {
return;
}
$type = $atts['link_type'] ?? 'internal';
$url = '';
switch ($type) {
case 'internal' :
if (is_numeric($atts['link_' . $type])) {
// this is a post id and should be converted to a link
$url = get_permalink($atts['link_' . $type]);
} else {
// this is an archive link (and it should be left untouched)
$url = $atts['link_' . $type];
}
break;
case 'external' :
$url = $atts['link_' . $type];
break;
case 'onpage' :
$url = '#' . $atts['link_' . $type];
break;
}
$target = $atts['link_target'] ?? '_self';
$text = $atts['link_text'] ?: (($type == 'internal') ? get_the_title($atts['link_internal']) : '');
$class = $class ?: '';
if (is_admin() && !empty($text)) {
$text = __('Knoptekst niet ingevuld', 'nijstartertheme');
$class .= ' disabled';
}
return "<a href='{$url}' class='{$class}' target='{$target}'>{$text}</a>";
}
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.