0

I am trying to tidy up the post_class function.

I've managed to remove "hentry" class using the filter below, but I would also like to remove the "post-id", "type-" and "status-" classes as well. How can I use my filter to do this?

function lsmwp_remove_postclasses( $classes ) {
    $classes = array_diff( $classes, array( 'hentry' ) );
    return $classes;
}
add_filter( 'post_class','lsmwp_remove_postclasses' );
  • this sounds wrong. what would be a reason for doing such a thing? – Mark Kaplun Apr 27 '18 at 12:10
0

One way would be to use preg_match and remove classes that matches given patterns, but... Since we know $post_id, we can use your code with a tiny modification:

function lsmwp_remove_postclasses($classes, $class, $post_id) {
    $classes = array_diff( $classes, array(
        'hentry',
        'post-' . $post_id,
        'type-' . get_post_type($post_id),
        'status-' . get_post_status($post_id),
    ) );
    return $classes;
}
add_filter('post_class', 'lsmwp_remove_postclasses', 10, 3);
0
add_filter( 'post_class', 'remove_hentry_function', 20 );
function remove_hentry_function( $classes ) {
    if( ( $key = array_search( 'hentry', $classes ) ) !== false )
        unset( $classes[$key] );
    return $classes;
}

Here is reference

It removing the "hentry" class.

  • Hmm... I'm pretty sure that hentry class is already removed with code posted in question... – Krzysiek Dróżdż Apr 27 '18 at 11:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.