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
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 asked Jan 4, 2013 at 16:21 ChuckChuck 5231 gold badge9 silver badges24 bronze badges 4- can I ask why you'd like this? – Tom J Nowell ♦ Commented Jan 4, 2013 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 Commented Jan 4, 2013 at 18:54
- would it not make more sense to jsut say data-filter=category-".$category->slug ? – Tom J Nowell ♦ Commented Jan 4, 2013 at 20:10
- that's exactly what I mentioned doing in the comments to toscho's answer – Chuck Commented Jan 4, 2013 at 21:25
1 Answer
Reset to default 1You 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.