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 $return HTML-форматований коментар author link. Empty for an invalid URL.
* @param string $author The comment author's username.
* @param string $comment_ID Коментарі ID як numeric string.
*
* @return string
*/
function wp_kama_get_comment_author_link_filter( $return, $author, $comment_ID ){
// Filter...
return $return;
}- $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 | $author and $comment_ID parameters були added. |
Де викликається хук
get_comment_author_link