Site logo

[Support request] Dynamic Text External Link

Home Forums Support [Support request] Dynamic Text External Link

Home Forums Support Dynamic Text External Link

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #1908605
    Matt

    Hi Guys,

    Just wondering if there is a way to make dynamic text links open a new tab (ie. target=”_blank”)?

    Thanks

    #1908929
    David
    Staff
    Customer Support

    Hi there,

    select the Button link – beside the URL field, theres a 3 dot menu, select that and select Open Link in New Tab.

    #2207344
    Mats

    Hi!

    I’m only seeing the 3 dots when it’s a button element.
    Is there a way to open a text link (h2) in a new tab?

    #2207564
    David
    Staff
    Customer Support

    Hi there,

    there isn’t the option for that, where is the link stored ?

    #2207611
    Mats

    It is a header (H2) with dynamic text and a dynamic link from meta fields.

    #2207938
    David
    Staff
    Customer Support

    Hmmm…. i think this would be easier to create a shortcode then it would be to filter the rel attribute in.
    A PHP Snippet like this for the shortcode:

    
    add_shortcode('db_meta_link', function() {
        $url = get_post_meta( get_the_ID(), 'url-meta-key', true );
        $text = get_post_meta( get_the_ID(), 'text-meta-key', true );
        
        $html = '<a href="' . $url . '" rel="_blank">' . $text . '</a>';
        
        return $html;
    } );

    Then you can add the [db_meta_link] inside the Headline Block.

    #2208530
    Mats

    Ok, that looks good.

    I’ll just need to input the meta keys into the shortcode coz it’s not always the same.

    #2208662
    David
    Staff
    Customer Support

    Ok so give this shortcode a try:

    function custom_meta_link( $atts ) {
    
        $atts = shortcode_atts(
            array(
                'text' => '',
    			'link' => '',
            ), $atts, 'custom_field_display' 
        );
    
        $html = '';
        $text = get_post_meta(get_the_id(), $atts['text'], true);
        $link = get_post_meta(get_the_id(), $atts['link'], true);
    	
        if(!empty($text) && !empty($link) ){
            $html = sprintf('<a href="%2$s">%1$s</a>', $text, $link );
        }
    
        return $html;
    }
    add_shortcode( 'db_meta_link', 'custom_meta_link' );

    Now you can do:

    [db_meta_link text="your_text_meta_key" link="your_link_meta_key"]

Viewing 8 posts - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.