Jed La Rosa Jed La Rosa - 11 months ago 92
PHP Question

How to check the body tag if it has a class name of "single-product" using php?

I need an if statement that checks the body tag if it has a class name of "single-product" using php? I need to echo a function in a single product page only of woocommerce of wordpress.

This is the code that I would like to show only for single product pages that uses woocommerce.php

<div id="from_product_page">
<?php
$recent = new WP_Query("page_id=235");
while($recent->have_posts()) : $recent->the_post();?>
<?php the_title(); ?>
<?php the_content(); ?>
<?php endwhile; ?>
</div>

Answer Source

You can do something like this:--

$body_classes = get_body_class();
if(in_array('single-product', $body_classes))
{
    //Single product page
} else {
    //Other Page
}

get_body_class() will return all body classes with array...

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download