WordPress at a glance

comment_class() WP 1.0

Generates semantic classes for each comment element.

  • Since 4.4.0 Added the ability for $comment to also accept a WP_Comment object.
Works based on: get_comment_class()
✈ 1 time = 0.001315s = very slow | 50000 times = 2.64s = fast | PHP 7.0.5, WP 4.4.2

No Hooks.

Return

String. If $echo is false, the class will be returned. Void otherwise.

Usage

comment_class( $class, $comment, $post_id, $echo );
$class(string/array)
One or more classes to add to the class list.
Default: ''
$comment(int/WP_Comment)
Comment ID or WP_Comment object.
Default: current comment
$post_id(int/WP_Post)
Post ID or WP_Post object.
Default: current post
$echo(true/false)
Whether to cho or return the output.
Default: true

Code of comment_class: wp-includes/comment-template.php VER 5.0.1

<?php
function comment_class( $class = '', $comment = null, $post_id = null, $echo = true ) {
	// Separates classes with a single space, collates classes for comment DIV
	$class = 'class="' . join( ' ', get_comment_class( $class, $comment, $post_id ) ) . '"';
	if ( $echo)
		echo $class;
	else
		return $class;
}

Related Functions

From tag: Decor (design, layout, styling, class)

More from category: Comments Loop

More from Template Tags: Comments

No comments
    Hello, !     Log In . Register