0

I am trying to list out all of the current page body classes. using the body_class function it gave me class="[body classes were here]" however I need to show these as plain text. I have tried the get_body_class function however it is an array.

How would I go about pulling the current page/post body classes from this?

https://codex.wordpress.org/Function_Reference/body_class https://codex.wordpress.org/Function_Reference/get_body_class

Current Code:

$parentTitle = get_the_title($post->post_parent);
$parentID = get_the_ID($post->post_parent);
$currentTitle = get_the_title($post);
$currentID = get_the_ID();
$bodyclasses = get_body_class($post);
    foreach ($bodyclasses as $currentBodyClass)
echo "
<div id='plugin-PageInfo' class='clearfix'>
    <div id='plugin-PageInfo-click'>
        <i class='fa fa-cog'></i>
    </div>
    <div id='slideOutContainer'>
        <div id='slideContent'>"
        . $parentTitle . $parentID . $currentTitle . $currentID . $currentBodyClass .
        "</div>
    </div>
</div>
";

Amended, Working Code:

$parentTitle = get_the_title($post->post_parent);
$parentID = get_the_ID($post->post_parent);
$currentTitle = get_the_title($post);
$currentID = get_the_ID();
$bodyclasses = get_body_class($post);

echo "
<div id='plugin-PageInfo' class='clearfix'>
    <div id='plugin-PageInfo-click'>
        <i class='fa fa-cog'></i>
    </div>
    <div id='slideOutContainer'>
        <div id='slideContent'>"
        . $parentTitle . $parentID . $currentTitle . $currentID .''; 
        foreach ($bodyclasses as $currentBodyClass) {
    echo "$currentBodyClass<br />\n";
}    
    echo    "</div>
    </div>
</div>
";
0
$bodyclasses = get_body_class();
foreach ($bodyclasses as $class)
        echo $class;
  • I only seem to get this output using that: no-customize-support – Ben H Feb 18 '16 at 0:03
  • I had to amend slightly but got it working using: foreach ($bodyclasses as $currentBodyClass) { echo "$currentBodyClass<br />\n"; } – Ben H Feb 18 '16 at 0:07

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.