#18: pre_link_description

The pre_link_description filter allows you to do modify a link’s description before it is saved into the database.

It is evaluated in sanitize_bookmark_field() under the db context, which is used in wp_insert_link() in the wp-admin/includes/bookmark.php file.

You should run any string text you return via this filter through esc_attr() as it’s used in the link’s title attribute. See the note below about slashing link data.

pre_link_description accepts a single argument in the form of a string containing the link description/title attribute.

Side note: Link data coming out of the database via wp_insert_link() is unslashed via wp_unslash() in 3.6+ (stripslashes_deep() in older versions) but the data going in will automatically be slashed via mysql_real_escape_string() in the $wpdb->insert|prepare methods (thanks Rarst for the assist!). In other words, this is a case where Core handles slashing the data for you.


Let’s say you run a site that still actively uses the Link Manager to build a blog roll or links list, and let’s say you want to subtly indicate when a link was last edited. The following replaces the link description with the last-edited date and time which is then saved in the database.

View the code example on Gist.