Pass php variable to CSS code within php file

$a = "ABCD";

?>
    <link rel='stylesheet' type='text/css' href='others.php' />
    <style>
        .page-title {
            text-indent: -9999px;
            line-height: 0;
        }
        .page-title:after {
            content: <?php echo $a; ?>;
        }
    </style>
<?php
  • It's a .php file and I need to pass "ABCD" to the content of the CSS as above.
  • I don't want to keep an extra .php or .css file.

Answer

Solution:

The value of the content style needs to be in quotes, unless it's one of the special keywords.

$a = "ABCD";

?>
    <link rel='stylesheet' type='text/css' href='others.php' />
    <style>
        .page-title {
            text-indent: -9999px;
            line-height: 0;
        }
        .page-title:after {
            content: "<?php echo $a; ?>";
        }
    </style>
<?php

Source