Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

188
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda