get_comment_author_link
Позволяет изменить ссылку на сайт комментатора, возвращаемую функцией get_comment_author_link().
Использование
add_filter( 'get_comment_author_link', 'wp_kama_get_comment_author_link_filter', 10, 3 ); /** * Function for `get_comment_author_link` filter-hook. * * @param string $comment_author_link The HTML-formatted comment author link. Empty for an invalid URL. * @param string $comment_author The comment author's username. * @param string $comment_id The comment ID as a numeric string. * * @return string */ function wp_kama_get_comment_author_link_filter( $comment_author_link, $comment_author, $comment_id ){ // filter... return $comment_author_link; }
- $return(строка)
- Ссылка на сайт комментатора в html формате (<a></a>), если она была указана и корректна. Иначе - имя автора комментария.
- $author(строка)
- Имя автора комментария, получаемое функцией get_comment_author().
- $comment_ID(число)
- ID комментария.
Примеры
#1 Изменяет ссылку, чтобы она открывалась в новой вкладке.
Добавим к ссылке атрибут target='_blank':
add_filter( 'get_comment_author_link', 'add_target_blank_comment_author_link' ); function add_target_blank_comment_author_link( $return ) { $search = 'external nofollow\''; $replace = 'external nofollow noreferrer\' target=\'_blank\''; return str_replace( $search, $replace, $return ); }
Заметки
- C версии 4.1.0 Добавлены параметры $author и $comment_ID.
Список изменений
С версии 1.5.0 | Введена. |
С версии 4.1.0 | The $comment_author and $comment_id parameters were added. |
Где вызывается хук
get_comment_author_link
wp-includes/comment-template.php 293
return apply_filters( 'get_comment_author_link', $comment_author_link, $comment_author, $comment_id );