PHP add class to html div
61,239
Solution 1
Try this code :
<div class="to-do to-do-wrap<?php echo get_field('to-do-repeater') ? ' complete' : '' ?>"></div>
Solution 2
<?php
echo "<div class=\"to-do to-do-wrap ";
if(get_field('to-do-repeater'))
{
echo "complete";
}
echo " \"></div>";
?>
Author by
Pullapooh
Updated on August 08, 2020Comments
-
Pullapooh almost 4 years
i would like to add a class to my html (.complete) with php:
if( get_field('to-do-repeater') ) { Add (complete) class to <div class="to-do to-do-wrap"> should be <div class="to-do to-do-wrap complete"> } else { Do nothing }
-
Pullapooh almost 12 yearsthere is already a div
code <div class="to-do to-do-wrap"></div>
i would like to add a new class name to it whit php called complete. I am using wordpress advanced custom fields true or false ( [link] advancedcustomfields.com/docs/field-types/true-false)
-
-
Pullapooh almost 12 yearsif( get_field('to-do-repeater') ) { Add (complete) class to <div class="to-do to-do-wrap"> should be <div class="to-do to-do-wrap complete"> }
-
Oussama Jilal almost 12 yearsthis is HTML and in it there is a php tag (<?php ?>) . Replace your code with this one I wrote
-
Pullapooh almost 12 yearsthis is not working it is adding a new div i would like to only add a complete class name to an already existing div : )
-
PriestVallon almost 12 yearsYou can remove the existing div that has the classes "to-do to-do-wrap" and replace it with my code.
-
Pullapooh almost 12 yearsyes it is working super perfectly now thanks so much Yazmat : )
-
Pullapooh almost 12 yearsooh yes that's true now it is working too thanks PriestVallon : )