How do I use a custom title attribute in Autolink created links?
Link Whisper
Last Update a year ago
By default, the Autolinking will use the keyword as the link’s “title” attribute. So when a user hovers the mouse over the link, the “title” bubble that pops up will contain the keyword text.
But sometimes, you want to use a custom title for the created autolinks. In those cases, we have a filter to allow you to adjust the title before it’s inserted in the content. (This only works before the link is created, existing links won’t be updated with new titles.)
The filter is called “wpil_filter_autolink_title”, and it provides 3 arguments.
- The original title that Link Whisper was going to insert in the link. (The autolink keyword)
- The data object that link is going to be inserted in. It can be either a WordPress Post or a Term object.
- The Link Whisper keyword data object that contains all of the autolink’s creation data.
To see it in action, here is how to filter the autolink title so that instead of using the “keyword” as the title, the target post’s title will be used.
Since this is custom code, you will need to put it in a code snippet plugin or carefully enter it in the functions.php file of your site’s child theme. (Don’t put it in the parent theme’s functions.php file or it will be overwritten when you update the theme)
