ThemeForest

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

201 posts
  • Has been a member for 2-3 years
  • Sold between 10 000 and 50 000 dollars
  • Bought between 50 and 99 items
  • Referred between 10 and 49 users
  • Exclusive Author
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!

2470 posts Nice Guy
  • Most Wanted Bounty Winner
  • Elite Author
  • Sold between 250 000 and 1 000 000 dollars
  • Has been a member for 5-6 years
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
  • Won a Competition
  • Bought between 100 and 499 items
  • Exclusive Author
  • Referred between 200 and 499 users
+4 more
RubenBristian 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..).

374 posts
  • Microlancer Beta Tester
  • Elite Author
  • Sold between 250 000 and 1 000 000 dollars
  • Most Wanted Bounty Winner
  • Has been a member for 3-4 years
  • Referred between 200 and 499 users
  • Bought between 10 and 49 items
  • Netherlands
+1 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
  • Europe
  • Exclusive Author
  • Has been a member for 0-1 years
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. :)

374 posts
  • Bought between 50 and 99 items
  • Europe
  • Exclusive Author
  • Has been a member for 1-2 years
  • Sold between 5 000 and 10 000 dollars
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?

201 posts
  • Has been a member for 2-3 years
  • Sold between 10 000 and 50 000 dollars
  • Bought between 50 and 99 items
  • Referred between 10 and 49 users
  • Exclusive Author
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..

273 posts
  • Bought between 1 and 9 items
  • Has been a member for 2-3 years
  • Microlancer Beta Tester
  • United Kingdom
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.

2470 posts Nice Guy
  • Most Wanted Bounty Winner
  • Elite Author
  • Sold between 250 000 and 1 000 000 dollars
  • Has been a member for 5-6 years
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
  • Won a Competition
  • Bought between 100 and 499 items
  • Exclusive Author
  • Referred between 200 and 499 users
+4 more
RubenBristian 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..
2355 posts
  • Has been a member for 4-5 years
  • Exclusive Author
  • Europe
  • Bought between 10 and 49 items
  • Referred between 100 and 199 users
  • Sold between 100 and 1 000 dollars
  • Microlancer Beta Tester
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">
383 posts
  • Elite Author
  • Sold between 100 000 and 250 000 dollars
  • Won a Competition
  • Referred between 500 and 999 users
  • Author had a Free File of the Month
  • Author had a File in an Envato Bundle
  • Bought between 10 and 49 items
+3 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