Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

175
Views
Remove "first" and "last" CSS classes from WooCommerce product loop

I'm using a filter to remove the "first" and "last" classes from the product-grid.

When I set $classes to NULL it removes all of them, but my code should remove just the two. But that doesn't work.

add_filter( 'post_class', 'prefix_post_class', 21 );
function prefix_post_class( $classes ) {
    if ( 'product' == get_post_type() ) {
        $classes = array_diff( $classes, array( 'first', 'last' ) );
        // $classes = NULL; <-- This works strangely enough
    }
    return $classes;
}
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

You can use the WooCommerce Post Class filter instead.

So you get:

/**
 * WooCommerce Post Class filter.
 *
 * @since 3.6.2
 * @param array      $classes Array of CSS classes.
 * @param WC_Product $product Product object.
 */
function filter_woocommerce_post_class( $classes, $product ) {
    // array_values() returns all the values from the array and indexes the array numerically.
    // array_diff - Compares array against one or more other arrays and returns the values in array that are not present in any of the other arrays.
    $classes = array_values( array_diff( $classes, array( 'first', 'last' ) ) );
    
    return $classes;
}
add_filter( 'woocommerce_post_class', 'filter_woocommerce_post_class', 10, 2 );
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!