Главная Новости

Comments_popup_link_attributes — Фильтрует атрибуты ссылки, которую выводит функция comments_popup_link(). Хук-фильтр WordPress

Опубликовано: 13.02.2018

Фильтрует атрибуты ссылки, которую выводит функция comments_popup_link() .

Использование

add_filter( 'comments_popup_link_attributes', 'filter_function_name_7126' ); function filter_function_name_7126( $attributes ){ // Фильтруем... return $attributes; } $attributes(cтрока) Атрибуты ссылки.

По умолчанию: ''

Примеры

#1 Добавим свой data атрибут

Добавит атрибут data-postid с ID записи.

add_filter( 'comments_popup_link_attributes', 'filter_comments_popup_link_attributes' ); function filter_comments_popup_link_attributes( $attrs ) { $my_attr = sprintf( 'data-postid="%d"', get_the_ID() ); return $attrs ? "$attrs $my_attr" : $my_attr; }

Где используется хук

... } echo '"'; if ( !empty( $css_class ) ) { echo ' class="'.$css_class.'" '; } $attributes = ''; /** * Filters the comments link attributes for display. * * @since 2.5.0 * * @param string $attributes The comments link attributes. Default empty. */ echo apply_filters( 'comments_popup_link_attributes', $attributes ); echo '>'; comments_number( $zero, $one, $more ); echo '</a>'; } /** * Retrieve HTML content for reply to comment link. * * @since 2.7.0 * @since 4.4.0 Added the ability for `$comment` to also accept a WP_Comment object. * * @param array $args { * Optional. Override default arguments. * ... campusboy 2826 — youtube.com/c/wpplus

Создатель YouTube канала wp-plus, на котором делюсь своими опытом. Активный пользователь wp-kama.ru. WordPress-разработчик. Разработка сайтов и лендингов. Доработка существующих проектов. Сопровождение ресурсов.

rss