The goal is to add some internal styles to a function. The function has some if statements, and then it does:
$content .= "
<div>
<h3>stuff</h3>
<div>$additional_stuff</div>
</div>";
endwhile;
I'd like to put some styles
in there, too, so it loads when the h3 and additional_stuff loads, but my attempts ways just break it.
The goal is to add some internal styles to a function. The function has some if statements, and then it does:
$content .= "
<div>
<h3>stuff</h3>
<div>$additional_stuff</div>
</div>";
endwhile;
I'd like to put some styles
in there, too, so it loads when the h3 and additional_stuff loads, but my attempts ways just break it.
Share Improve this question edited Oct 21, 2018 at 14:27 Tiago Peres 951 gold badge1 silver badge11 bronze badges asked Oct 20, 2018 at 17:25 Justin MunceJustin Munce 31 bronze badge1 Answer
Reset to default 0Here's couple of examples on how to add styling to your code.
// Method 1. define classes in another variable, then do styling in styles.css
$classes = 'another-class';
$content .= "
<div id=\"my-id\"class=\"my-class\"> // Method 2. use backslashes to escape double quotes and add id and classes as needed, then do styling in styles.css
<h3 class=\"{$classes}\">stuff</h3> // Method 1. interpolate classes where needed
<div style=\"background-color: blue; color: #fff;\">{$additional_stuff}</div> // Method 3. use backslashes to escape double quotes and add inline styles
</div>";
p.s. do remove the comments from the example code before copy-pasting $content
to production.