0

Can't see to update my style.php file with the following

Here is my style.php coding..

<?php header("Content-type: text/css; charset: UTF-8");
$fontColor = "#<?php echo get_option('mwg_font_paragraph'); ?>";
?>

#content p {
color: <?php echo $fontColor; ?>;
}

If clear out that link and manually enter a color, it works fine:

$fontColor = "#FF0000";

Any suggestions would be greatly appreciated..

Nirpendra Patel
  • 659
  • 7
  • 20
mwgideon
  • 57
  • 2
  • 11
  • You can't do PHP inside PHP like that. `$fontColor = "#" . get_option('mwg_font_paragraph');` or `color: #;` - either one will do the trick. – ceejayoz May 13 '16 at 03:33

2 Answers2

1

As Nirpendra stated, you're using PHP inside PHP. Your code should look like this instead:

<?php header("Content-type: text/css; charset: UTF-8");
$fontColor = "#" . get_option('mwg_font_paragraph');
?>

#content p {
color: <?php echo $fontColor; ?>;
}

When you want to concatenate (join) multiple values together in PHP, whether they be strings, function calls, variables or something else, you need to use the . to join them, rather than nest additional PHP tags.

All the <?php ... ?> tags do is indicate what code PHP should parse, and when you're inside those tags, it's already parsing what you write.

Tim Malone
  • 3,364
  • 5
  • 37
  • 50
  • First - thanks for helping out on this one.. I tried the coding you recommended, but it's still adjusting the font color based on the get_option.. like I said if I just put in the font color - it works, but for some reason it's not pulling the information from the theme option. I've even double checked the option name.. – mwgideon May 13 '16 at 03:47
  • Ohh, got ya. It's most likely because this file isn't part of the Wordpress ecosystem. Can you see any errors when you visit it directly? Try doing what [this answer](http://stackoverflow.com/a/15306647/1982136) says - you may need to adjust the path depending on how your theme is set up. – Tim Malone May 13 '16 at 04:28
  • How did you go with this @user3096500? – Tim Malone Jun 14 '16 at 22:30
0

You are using nested php inside php in your first line.

Nirpendra Patel
  • 659
  • 7
  • 20