The next_comments_link_attributes WordPress PHP filter allows you to modify the anchor tag attributes for the next comments page link.
Usage
add_filter('next_comments_link_attributes', 'custom_next_comments_link_attributes'); function custom_next_comments_link_attributes($attributes) { // your custom code here return $attributes; }
Parameters
$attributes
(string) – The attributes for the anchor tag.
More information
See WordPress Developer Resources: next_comments_link_attributes
Examples
Adding a CSS class to the next comments link
Add a class to the anchor tag for styling purposes.
function add_class_to_next_comments_link($attributes) { $attributes .= ' class="custom-next-comments-link"'; return $attributes; } add_filter('next_comments_link_attributes', 'add_class_to_next_comments_link');
Adding a custom title attribute
Add a custom title attribute to the anchor tag for accessibility purposes.
function add_title_to_next_comments_link($attributes) { $attributes .= ' title="Next comments page"'; return $attributes; } add_filter('next_comments_link_attributes', 'add_title_to_next_comments_link');
Adding a custom data attribute
Add a custom data attribute to the anchor tag for JavaScript purposes.
function add_data_attribute_to_next_comments_link($attributes) { $attributes .= ' data-custom-attribute="custom-value"'; return $attributes; } add_filter('next_comments_link_attributes', 'add_data_attribute_to_next_comments_link');
Modifying existing attributes
Modify the existing attributes of the anchor tag.
function modify_next_comments_link_attributes($attributes) { $attributes = str_replace('existing-attribute', 'new-attribute', $attributes); return $attributes; } add_filter('next_comments_link_attributes', 'modify_next_comments_link_attributes');
Combining multiple attributes
Add and modify multiple attributes for the anchor tag.
function customize_next_comments_link_attributes($attributes) { $attributes .= ' class="custom-next-comments-link"'; $attributes .= ' title="Next comments page"'; $attributes = str_replace('existing-attribute', 'new-attribute', $attributes); return $attributes; } add_filter('next_comments_link_attributes', 'customize_next_comments_link_attributes');