Forums

[resolved] the class names in comment_class() (3 posts)

  1. Danielx64
    Member
    Posted 1 year ago #

    Hello,

    I been reading http://wordpress.org/support/topic/editing-the-classes-in-comment_class?replies=10 & http://codex.wordpress.org/Template_Tags/comment_class and I'm wondering if anyone got any example code that will rename 2 classes without having to hack the wordpress core.

    I'm working on a theme where I want the class names that was used on a phpbb theme to match as close as it can be.

    I would like to change the even to bg1 and odd to bg2.

    Please note that thread-even and thread-odd need to stay there.

    Regards,

    Daniel

  2. stevejohnson
    Member
    Posted 1 year ago #

    Use a variation of what Mark posted in the other thread:

    function change_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 it's 'even' or 'odd', change
    			## if not, leave it alone
    			case 'even':
    				$classes[$key] = "bg1";
    				break;
    
    			case 'odd':
    				$classes[$key] = "bg2";
    				break;
    
    			default:
    				continue;
    		}
    	}
    	// Clean out the variables no longer needed
    	unset($key,$class);
    	// Return the result
    	return $classes;
    }
    add_filter( 'comment_class' , 'change_comment_classes' );

    Note that you don't strictly have to use the 'default' case, but a lot of people like to see it for clarity.

  3. Danielx64
    Member
    Posted 1 year ago #

    Hello,

    I just tried out your code, and it works :)

    Thankyou :)

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.