I have created a table at Single Product Page
via plugin
.
I want to change the color
, border
, bg-color
etc.. according to the values that the admin will set/enter from dashboard
.
I have done the following so far.
From the following form (attached image)
, the admin will choose the css
values for table body
, header
etc.And after hitting the save
button, all those css
values will be saved inin wp_options
as key value
pair.
For Example
'table_background_color' => '#ff5'
What I want
I don't want to get the wp_option
and then apply that css design value
for particular element of the table
, because I have huge form containing a lot of css
design
values and applying css inline is kind of messy.
I'm looking for some nice approach to apply those css
values (which I have saved in wp_options)
to the table.
How can I apply those saved css values
from a separate file ?
Any help/recommendation will be highly appreciated, thanks.
I have created a table at Single Product Page
via plugin
.
I want to change the color
, border
, bg-color
etc.. according to the values that the admin will set/enter from dashboard
.
I have done the following so far.
From the following form (attached image)
, the admin will choose the css
values for table body
, header
etc.And after hitting the save
button, all those css
values will be saved inin wp_options
as key value
pair.
For Example
'table_background_color' => '#ff5'
What I want
I don't want to get the wp_option
and then apply that css design value
for particular element of the table
, because I have huge form containing a lot of css
design
values and applying css inline is kind of messy.
I'm looking for some nice approach to apply those css
values (which I have saved in wp_options)
to the table.
How can I apply those saved css values
from a separate file ?
Any help/recommendation will be highly appreciated, thanks.
1 Answer
Reset to default 0There's a discussion of a very similar question here.
As in that question, there are a few suggested options, each with their own pros and cons.
For what you describe, it sounds like you might want to consider the idea of generating a CSS file every time the admin changes any settings on this page. This is the fastest option because you don't need to re-do this work on every page load.
I'm not sure if there's an easy way to do this (perhaps someone else will know a way), so if you like that approach it seems like you need to do these steps:
- Make sure that from PHP you can write to a .css file somewhere. Perhaps make a new plugin for this feature and put the code and generated CSS file in the plugin.
- Make sure that the .css file can be easily enqueue'd from Wordpress
- Write a script which takes all of your options from
wp_options
and writes a complete CSS file - Hook that script so that it re-generates the CSS every time the admin page is saved.
HTH