post_class remove tag- or category- from slug

I've got this in my theme

article ?php post_class('archiveMain'); ?

But for tags and categories it adds tag- or category- before the slug, any way to remove that?

Example: tag-sales would just be sales, category-webinar, just webinar

Topic tags categories post-class Wordpress

Category Web


You can filter post_class and change these class names:

add_filter( 'post_class', 'wpse_78237_post_class' );

function wpse_78237_post_class( $classes )
{
    $out = array ();

    foreach ( $classes as $class )
    {
        if ( 0 === strpos( $class, 'tag-' ) )
        {
            $out[] = substr( $class, 4 );
        }
        elseif ( 0 === strpos( $class, 'category-' ) )
        {
            $out[] = substr( $class, 9 );
        }
        else
        {
            $out[] = $class;
        }
    }

    return array_unique( $out );
}

But be aware this could result in collisions with other class names, in body_class for example. I would not do that.

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.