5

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
}
1
  • there 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) Commented Aug 7, 2012 at 19:38

3 Answers 3

9

Try this code :

<div class="to-do to-do-wrap<?php echo get_field('to-do-repeater') ? ' complete' : '' ?>"></div>
Sign up to request clarification or add additional context in comments.

3 Comments

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"> }
this is HTML and in it there is a php tag (<?php ?>) . Replace your code with this one I wrote
yes it is working super perfectly now thanks so much Yazmat : )
4
<?php

echo "<div class=\"to-do to-do-wrap ";
if(get_field('to-do-repeater'))
{
    echo "complete";
}
echo " \"></div>";

?>

3 Comments

this is not working it is adding a new div i would like to only add a complete class name to an already existing div : )
You can remove the existing div that has the classes "to-do to-do-wrap" and replace it with my code.
ooh yes that's true now it is working too thanks PriestVallon : )
0

Try this code:

<div class="to-do to-do-wrap <?php if(get_field('to-do-repeater') echo "complete"?>">

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.