Support

Account

Home Forums General Issues Make the URL the text link in Link field

Solved

Make the URL the text link in Link field

  • that’s probably not a very good title, but what i’d like to do is have whatever the user inputs into the url field – appear as the link text.
    so instead of ‘website’ it’d be https://www.domain.com (or whatever the url is they input.
    this is what i’m using currently:

    <?php 
    $link = get_field('link');
    if( $link ): ?>
        <a href="<?php echo esc_url( $link ); ?>">Website</a>
    <?php endif; ?>

    i know this will be simple, so thanks for your patience…

  • answered my own question, used the array:

    <?php 
    $link = get_field('link');
    if( $link ): 
        $link_url = $link['url'];
        $link_title = $link['title'];
        $link_target = $link['target'] ? $link['target'] : '_self';
        ?>
        <a href="<?php echo esc_url( $link_url ); ?>" target="<?php echo esc_attr( $link_target ); ?>"><?php echo esc_html( $link_title ); ?></a>
    <?php endif; ?>
Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.