Support

Account

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>";
    }