Home » Wordpress » can I save CSS values in my WordPress theme without a MySQL table?

can I save CSS values in my WordPress theme without a MySQL table?

Posted by: admin November 30, 2017 Leave a comment

Questions:

I am a little bit of a newbie at WordPress theme development, and I can’t find the answer here or through much Google foo, so I wanted to find out if this scenario is possible.

I’m writing a child theme for Themetatic and I wanted to provide end users with the ability to change CSS color values and font family from a dialoge box in the theme controls. Does this require storing their entries in the database or can I just store these directly in the CSS file?

Answers:

No, you will need to create a theme_option that WP will store in the database and an interface for the user to edit these options.

There is a great tutorial on how to do all of this here.

Questions:
Answers:

No you don’t need to store them in the database. you can do something like this:

html:

<a id="style1" href="?view=black"></a>
<a id="style2" class="current" href="yourwebsite.com"></a>

and put the following in the header.php

if(isset($_GET['view'])) {

 <link href="style1.css" rel="stylesheet" media="screen">

} else {

<link href="style2.css" rel="stylesheet" media="screen">

}

Questions:
Answers:

The way I would go about doing this would be by creating a Dynamic CSS file after the color/font values have been changed. Your CSS file would then be re-created to include these changed values.