How to properly apply WordPress's theme options to CSS and JavaScript in a page?

500 posts Keep Walking
  • Trendsetter
  • 4 Years of Membership
  • Elite Author
  • Author Level 9
+5 more
UXbarn
says

Most theme options were created and saved on PHP and I don’t know what is the proper way to apply those saved options to the CSS and JavaScript of the WordPress theme. Right now the CSS and JavaScript codes are all in the external files.

I was thinking of doing echo those options right away in the <script> or <style> block but maybe that isn’t a good practical way to do? :|

Please advise.. :confused:

Thanks in advanced!

3804 posts
  • Elite Author
  • Author Level 11
  • Trendsetter
  • 7 Years of Membership
+12 more
KrownThemes
says

Don’t put the theme options in the header. It’s not a good practice and it will just increase your header without any good reason.

You should do those changes directly inside the css files(for colors, backgrounds, etc..).

381 posts
  • Weekly Top Seller
  • Elite Author
  • Most Wanted Winner
  • Author Level 10
+7 more
redfactory
says

We have an extra style.php file in which the options are echoed directly into the css. Make sure to only have the css that needs changing in that file, and to load it as last so it overwrites your default css rules.

Good luck :)

13 posts
  • 3 Years of Membership
  • Exclusive Author
xiaSKULL
says

We have an extra style.php file in which the options are echoed directly into the css. Make sure to only have the css that needs changing in that file, and to load it as last so it overwrites your default css rules. Good luck :)

+1. :)

438 posts
  • 3 Years of Membership
  • Author Level 4
  • Collector Level 3
  • Exclusive Author
Pixelous
says

We have an extra style.php file in which the options are echoed directly into the css. Make sure to only have the css that needs changing in that file, and to load it as last so it overwrites your default css rules. Good luck :)

So, your style.php generate a style.css, right?

500 posts Keep Walking
  • Trendsetter
  • 4 Years of Membership
  • Elite Author
  • Author Level 9
+5 more
UXbarn
says

Don’t put the theme options in the header. It’s not a good practice and it will just increase your header without any good reason. You should do those changes directly inside the css files(for colors, backgrounds, etc..).

Then how could I apply those css changes to the css files dynamically? I just a bit confuse at this point..

1096 posts
  • 5 Years of Membership
  • Affiliate Level 1
  • Beta Tester
  • Collector Level 2
+5 more
Gareth_Gillman
says

you would use the php file_open and write functions, this will enable the script to open the css file and save the contents to the file.

3804 posts
  • Elite Author
  • Author Level 11
  • Trendsetter
  • 7 Years of Membership
+12 more
KrownThemes
says

you would use the php file_open and write functions, this will enable the script to open the css file and save the contents to the file.
Exactly! This is how i do it..
2468 posts
  • 6 Years of Membership
  • Author Level 2
  • Affiliate Level 4
  • Beta Tester
+3 more
digitalimpact
says

So nobody sets the headers for customstyles.php to

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

, adding it as any other external CSS to the head?
<link rel="styleheet" href="<?php bloginfo('stylesheet_directory'); ?>/customstyles.php" media="screen">
501 posts
  • Affiliate Level 7
  • Author Level 10
  • Collector Level 2
  • Top Monthly Author
+10 more
pixelentity
says

To echo custom rules inside a style block of header is not a bad practice and also has absolutely zero impact on performances/load times while to write an external css file with custom values requires an additional server request which is far more costly in terms of resources.

BF

by
by
by
by
by
by