tailwind v3, How to use arbitrary color value in php echo?

Viewed 96

"#1FFFC6" and "#4C59FF" are custom colors picked from some color picker in wordpress backend.

if i write the code below directly, it works just fine.

<h1 class="bg-[#1FFFC6] text-[#4C59FF]"> h1 title </h1>

but, this one not working.

$nav_bgcolor = "#1FFFC6";
$nav_textcolor = "#4C59FF";
echo "<h1 class='bg-[$nav_bgcolor] text-[$nav_textcolor]'>title</h1>";

is there any way i can do this by using tailwind and php echo? please help, thanks.

env : php7.4, tailwind v3, vscode.

3 Answers

You need to add a space between h1 and class.

echo "<h1 class='bg-[$nav_bgcolor] text-[$nav_textcolor]'>title</h1>";

You can use the following code (according to the computer):


<?php

$nav_bgcolor = "#1FFFC6";
$nav_textcolor = "#4C59FF";

echo "<h1 class='bg-".$nav_bgcolor." text-".$nav_textcolor."'>title</h1>";

?>

Related