Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change css value with php

Tags:

css

php

how can I change css of a div displaying some text on my home page from the admin are. I want when I enter a color code in my plugin admin page, the code is updated in the css file. This is a common thing, but can't get a grasp of it.

so here is the css of my div.

#div{

background: #0000;

}

and here is the php code for my admin section.

<?php 
 Background Color: <input type="text" size="20" name="background"
 value="<?php get_option('backgroundchanges');?>"/>

so basically I want the value that I enter in the input to be reflected in the css file.

thanks for any help.

regards, :)

-ROn.

like image 916
Ronny K Avatar asked Jun 08 '12 14:06

Ronny K


1 Answers

You should actually not use a .css file and instead use a .php file acting as a .css file. Then you can just set the new color to a variable in the .php css file.

Rename your style.css file to style.php, then add the following to the top of the file:

<?php header("Content-type: text/css"); ?>

This line tells the browser that the file is CSS instead of HTML. In your HTML files, change the stylesheet references from style.css to style.php. For example:

<link rel="stylesheet" type="text/css"
 media="screen" href="style.php">

citation: http://www.barelyfitz.com/projects/csscolor/

like image 85
Steve Avatar answered Sep 20 '22 23:09

Steve