Question

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

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with wordpress.stackexchange
scroll top