WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

share|improve this question
can I ask why you'd like this? – Tom J Nowell Jan 4 '13 at 16:31
I'm going to be working with isotope to do some filtering, isotope.metafizzy.co/docs/filtering.html, I've built my links for filtering like this, <a href="#"data-filter=".'.$category->slug.'">'.$category->name.'</a>, I need to match $category->slug to the class but it appeared I was getting the slug with category or tag tacked on at the beginning. – Chuck Jan 4 '13 at 18:54
would it not make more sense to jsut say data-filter=category-".$category->slug ? – Tom J Nowell Jan 4 '13 at 20:10
that's exactly what I mentioned doing in the comments to toscho's answer – Chuck Jan 4 '13 at 21:25
up vote 0 down vote accepted

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 );
            $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.

share|improve this answer
Are you saying you wouldn't use something like this for body_class or that using this for post_class could cause issue with body_class? – Chuck Jan 4 '13 at 18:57
@Chuck Both. Just imagine a category sticky or a tag archive. The prefixes don’t hurt. – toscho Jan 4 '13 at 19:00
I see now what you are getting at. I guess I'll just add category- or tag- to the slug I'm trying to match to the post_class, and that will work just as well. Thanks for the answer, and for steering me away from using it. – Chuck Jan 4 '13 at 19:55

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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