Viewing 6 replies - 1 through 6 (of 6 total)
  • Can you be more descriptive about what you want to do?

    When you add a link to your post or on your template, it is already in an HTML tag.

    <a href="/blah/blah.php" title="blah description">blah</a>

    Do you want to add a class to make a specific link look different? Or do you want to style your links to look different than what are currently on your Theme?

    Be more specific and we’ll gladly give you more specific answers.

    Thread Starter alberto

    (@alberto)

    Hi Lorelle,
    I need asides pointing to interesting websites in the sidebar but I don’t want to mix normal posts with asides in the same database table. Instead I would prefer to use the link feature (see Link panel in WP Admin).

    So I created a new Link category named “Asides” which display a link and his description. The link points to the external resource (a good article, an interesting news, etc.) and is followed by a short description.

    So far no problem.

    But sometimes I would like to insert some HTML tags in the description (a, strong, em, etc.): unfortunately WP does not understand these tags and displays them in the final output.

    Any trick to insert HTML tags in link descriptions?

    (Of course I would like the link description not be placed in the title attribute of the a tag).

    I’d say nope as you can’t have html in link titles. It is not a WP issue. The description you see is used in the link title itself, WP just lets you display it separately.

    Thread Starter alberto

    (@alberto)

    Of course the description should not be used in the link title itself. The link does not need a title attribute since it is followed by a short description.

    I suppose it is necessary to edit the file links.php placed in the wp-includes folder.
    Here is an excerpt from the original code:


    $output = "";

    foreach ($results as $row) {
    if (!isset($row->recently_updated)) $row->recently_updated = false;
    $output .= ($before);

    if ($show_updated && $row->recently_updated) {
    $output .= get_settings('links_recently_updated_prepend');
    }

    $the_link = '#';

    if ( !empty($row->link_url) )
    $the_link = wp_specialchars($row->link_url);
    $rel = $row->link_rel;

    if ($rel != '') {
    $rel = " rel='$rel'";
    }

    $desc = wp_specialchars($row->link_description, ENT_QUOTES);
    $name = wp_specialchars($row->link_name, ENT_QUOTES);

    $title = $desc;

    if ($show_updated) {
    if (substr($row->link_updated_f,0,2) != '00') {
    $title .= ' (Last updated ' . date(get_settings('links_updated_date_format'), $row->link_updated_f + (get_settings('gmt_offset') * 3600)) .')';
    }
    }

    if ('' != $title) {
    $title = " title='$title'";
    }

    $alt = " alt='$name'";

    $target = $row->link_target;
    if ('' != $target) {
    $target = " target='$target'";
    }

    $output.= "<a href='$the_link'";
    $output.= $rel . $title . $target;
    $output.= '>';

    if (($row->link_image != null) && $show_images) {
    if (strstr($row->link_image, 'http'))
    $output.= "<img src='$row->link_image' $alt $title />";
    else // If it's a relative path
    $output.= "<img src='" . get_settings('siteurl') . "$row->link_image' $alt $title />";
    } else {
    $output.= $name;
    }

    $output.= '';

    if ($show_updated && $row->recently_updated) {
    $output.= get_settings('links_recently_updated_append');
    }

    if ($show_description && ($desc != '')) {
    $output.= $between.$desc;
    }
    $output.= "$after\n";
    } // end while

    if($echo) {
    echo $output;
    } else {
    return $output;
    }
    }

    Looks like you answered your own question. Whether it is necessary or not, obviously that is how it is. You’ll will have to edit the core file to get what you want. My bet it wp_specialchars encodes the < > so you will have to remove that.

    Thread Starter alberto

    (@alberto)

    Many thanks!
    I’ve just edited the links.php code as follows:

    OLD
    $desc = wp_specialchars($row->link_description, ENT_QUOTES);

    NEW
    $desc = $row->link_description;

    ****************************************

    OLD
    $output.= $rel . $title . $target;

    NEW
    $output.= $rel . $target;

    ****************************************

    Results: no title attribute in the a tag and html tags in the link description –> great asides (very short posts in the sidebar)!!!

    The only problem is that I have to repeat the hack each time I update WP…

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘HTML tags in link descriptions’ is closed to new replies.