• I’ve noticed by default, using comment_class() returns something like “comment even thread-even depth-1” to my comment class. Is there a place where I can edit these class names, or even remove some of them.

    For instance, I have no need for the alternating odd/even class schemes that are set up for this and would like to remove them, but I can’t seem to find where to do so.

    Any guidance is appreciated, thanks in advance.

Viewing 9 replies - 1 through 9 (of 9 total)
  • Hook a filter on “comment_class”..

    However, you don’t necessary need to do that because the function supports adding classes..

    See the codex page here.
    http://codex.wordpress.org/Template_Tags/comment_class

    Thread Starter ranji77

    (@ranji77)

    Thanks for replying t31os_.

    I’m aware that I can add new classes with comment_class(‘new_class’), but I don’t see anything in that link regarding how I can remove the default wordpress classes for comments (ie. class=”comment even thread-even depth-1″ ). Unless, “hooking” a filter would do that for me, but I’m not quite sure how to do it.

    I’ve tested a basic filter, it’s dead easy, but you’ll need to understand how to use arrays or know how to do some basic PHP..

    I can provide code to get you started, HOWEVER!.. if you prefer for me to write it, just tell me which classes you want gone and i’ll provide the code (take less then a minute).. 😉

    Thread Starter ranji77

    (@ranji77)

    As you can tell, my PHP knowledge is very limited but I’m always trying to learn myself before checking here 🙂

    I’d actually want all the classes removed except for “comment”

    The ones I see so far that I have no use for are “even” “odd” “thread-even” “thread-odd” “thread-alt” “depth-1” “alt”

    Thanks in advance, very much appreciated!

    Ok well there’s a few more then that, are you sure you want to remove them all, you may have style definitions for some of them in your theme.

    Just going to grab a cup of coffee and i’ll write a filter for you.. back in a few mins..

    Thread Starter ranji77

    (@ranji77)

    What are the other classes that you know of?

    As far as I can tell, the ones I listed above are the only classes showing up in my source code. I’m sure I’ll never use any of them as I like complete control over how my classes are assigned. Thanks again.

    Here you go..

    Sorry for the wait, had to feed the ginger creature before returning..

    function remove_comment_classes( $classes ) {
    
    	// Classes is an array of class names, so for each item - $array_key => $class_name
    	foreach( $classes as $key => $class ) {
    		// Check the class name
    		switch( $class ) {
    			// If the the class name is comment, move along
    			case 'comment':
    				continue;
    			// If it's anything else, unset the item from the array (remove)
    			default:
    				unset( $classes[$key] );
    				continue;
    			break;
    		}
    	}
    	// Clean out the variables no longer needed
    	unset($key,$class);
    	// Return the result
    	return $classes;
    }
    add_filter( 'comment_class' , 'remove_comment_classes' );

    Hope that helps…

    Thread Starter ranji77

    (@ranji77)

    You’re awesome t31! I added in a few more cases for my customized css classes and it works like a charm.

    Happy to help.. 🙂

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Editing the class names in comment_class()’ is closed to new replies.