Support » Plugin: Date Pagination » Add class names

  • polyfade

    (@polyfade)


    Is there an easy way to add class names to previous_posts_link and next_posts_link links?

Viewing 2 replies - 1 through 2 (of 2 total)
  • polyfade

    (@polyfade)

    This works for applying the same class name for each next and previous, but looking to apply different class names to each.

    function posts_link_attributes() {
        return 'class="link-more"';
    }
    
    add_filter('next_posts_link_attributes', 'posts_link_attributes');
    add_filter('previous_posts_link_attributes', 'posts_link_attributes');
    Plugin Author keesiemeijer

    (@keesiemeijer)

    Try it with the current_filter() function
    https://developer.wordpress.org/reference/functions/current_filter/

    
    function posts_link_attributes( $attributes ) {
    
    	// Check with current_filter what filter was used.
    	if ( 'next_posts_link_attributes' === current_filter() ) {
    		return 'class="next-class"';
    	}
    
    	return 'class="previous-class"';
    }
    
    add_filter( 'next_posts_link_attributes', 'posts_link_attributes' );
    add_filter( 'previous_posts_link_attributes', 'posts_link_attributes' );
    
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Add class names’ is closed to new replies.