Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

178
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda