• Resolved ThorHammer

    (@thorhammer)


    This code gets one url and one text from my custom fields and combines it to a link:

    <?php
    $link = get_post_meta($post->ID, 'link_url', true);
    $text = get_post_meta($post->ID, 'link_text', true);
     if ($link){
    echo '&nbsp;&middot; <a href="'.$link .'">'.$text.'</a>&nbsp;';
    }
    ?>

    I would like to add a title=”description of link”, but this is not possible through custom fields. I tried adding it as a variable in the template, but it was only the variable name itself which was echoed…

Viewing 4 replies - 1 through 4 (of 4 total)
  • imho, that would require a third custom field.

    <?php
    $link = get_post_meta($post->ID, 'link_url', true);
    $text = get_post_meta($post->ID, 'link_text', true);
    $descr = get_post_meta($post->ID, 'link_desc', true);
     if ($link){
    echo '&nbsp;&middot; <a href="'.$link .'"  title=".$descr.'">'.$text.'</a>&nbsp;';
    }
    ?>
    Thread Starter ThorHammer

    (@thorhammer)

    Thanks alchemyst!
    Also, it is possible to put the variable in the theme like this:
    $sinfo = 'title="Blah blah, this is the general link description" ';
    and adjust the echo like this:
    echo '&nbsp;&middot; <a href="'.$link.'" '.$sinfo.' >'.$text.'</a>&nbsp;';

    Versuch macht klug

    german proverb

    there does nothing seem to speak against it;
    the proverb freely translates to: ‘try it and you will know’

    Thread Starter ThorHammer

    (@thorhammer)

    Yep.. we got in Norwegian as well, almost the same construction 🙂

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Add title to a echoed URL’ is closed to new replies.