I am trying to use show post_class() within $output loop.Though i tried it different way i failed.

Here is my codes

$output = '<div ';
$output .= '" id=' . get_the_ID() . '>';

You should use get_post_class()

From Codex:

get_post_class() is not simply a non-echoing alternative to post_class(). get_post_class() does not return a string, but an array that must be processed to produce text similar to what is echoed by post_class().


$classes = get_post_class();
$output = '<div id="' . get_the_ID() . '" class="' . implode(" ", $classes) . '"></div>';

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.