Forums

Unable to add_filter on the "comment class". Hook fails? (1 post)

  1. Zanes
    Member
    Posted 10 months ago #

    Hello,

    I have been trying to hook into the wordpress comments to add classes to my comments.
    Following this topic's idea, I tried the simple code below (added in functions.php of my theme), which should change any class it encounters in the comment class :

    function change_comment_classes( $classes ) {
    	foreach( $classes as $key => $class ) {
    		switch( $class ) {
    		default:
    		//change the class' name to "new-comment-class-name"
    		$classes[$key] = "new-comment-class-name";
    		}
    	}
    	unset($key,$class);
    	return $classes;
    }
    add_filter( 'comment_class' , 'change_comment_classes');

    As you can see, this code is extremely simple, and it does not even work.
    An important thing to note is that I'm using the Monochrome theme, and that this theme seems to have a custom comment function in its functions.php.
    I've been wondering if this was the reason why my hook doesn't work.
    What I want to do is "add" an extra class to the comments, if they meet a particular requirement. But no point if this simple code doesn't work.

    Any help from knowledgeable people would be appreciated.

    Thanks,

    Zanes

Reply

You must log in to post.

About this Topic