1799 posts
  • Has referred 1+ members
  • Has sold $5,000+ on Envato Market
  • Has been a beta tester for an Envato feature
  • Has collected 10+ items on Envato Market
+4 more
BroOf says

I just finished my theme options today and everything works great. I can check them with “get_option(‘color’);” and it works, too!

Now I want to make my stylesheet dynamic so I created a file called “style.php”. I included it under the normal “style.css”.

BUT

when I try to use “get_option(‘color’);” it first said I didn’t defined the function. So I included at the very top of “style.php” this: “require_once(‘wp-blog-header.php’);”.

Now everything works and I can see that the informations in “style.php” are coreect but It doesn’t takes effect on my site^^

How do you create your dynamic stylesheets?

2580 posts Put a Donk On It
  • Has referred 200+ members
  • Has sold $250,000+ on Envato Market
  • Has collected 10+ items on Envato Market
  • Elite Author: Sold more than $75,000 on Envato Market
+10 more
ThemeProvince says

Just include it in the header.php its much easier.

1799 posts
  • Has referred 1+ members
  • Has sold $5,000+ on Envato Market
  • Has been a beta tester for an Envato feature
  • Has collected 10+ items on Envato Market
+4 more
BroOf says

Just include it in the header.php its much easier.

Yes but then all styling is done in the header section which isn’t good for SEO .

962 posts
  • Has been part of the Envato Community for over 5 years
  • Has sold $10,000+ on Envato Market
  • Has collected 100+ items on Envato Market
  • Sells items exclusively on Envato Market
+1 more
EireStudio says


Just include it in the header.php its much easier.
Yes but then all styling is done in the header section which isn’t good for SEO .

Where did you hear that? :D

1148 posts
  • Has referred 1+ members
  • Has sold $1,000+ on Envato Market
  • Has been a beta tester for an Envato feature
  • Has collected 10+ items on Envato Market
+3 more
fillerspace says



Just include it in the header.php its much easier.
Yes but then all styling is done in the header section which isn’t good for SEO .
Where did you hear that? :D

It definitely affects performance, as you aren’t able to take advantage of browser caching like you can in external stylesheets. With an external stylesheet, you can have the browser cache it for a month or more, and just use a query string for versioning.

How often are these settings going to change? Why not take the results of style.php and write them to a static file when the user saves the options? Then set up your theme to just include that file. You can do it very easily by using output buffering to capture the output of the php script, and use file_put_contents to save it to a file, say dynamic_style.css. To make sure you don’t serve an outdated version, just append a query string to it like this dynamic_style.css?ver=123 and increment that number every time you save it.

1799 posts
  • Has referred 1+ members
  • Has sold $5,000+ on Envato Market
  • Has been a beta tester for an Envato feature
  • Has collected 10+ items on Envato Market
+4 more
BroOf says



Just include it in the header.php its much easier.
Yes but then all styling is done in the header section which isn’t good for SEO .
Where did you hear that? :D

I think I heard it somewhere :) Is it common to do it this way? My last WordPress theme was developed before 2 years.

415 posts
  • Has referred 10+ members
  • Has sold $250,000+ on Envato Market
  • Has collected 10+ items on Envato Market
  • Elite Author: Sold more than $75,000 on Envato Market
+5 more
unisphere says

You’ll need to somehow include the wp-load.php core WordPress file in your skin.php file, then you’ll have access to the WordPress functions.

1028 posts
  • Has referred 500+ members
  • Has sold $500,000+ on Envato Market
  • Has collected 50+ items on Envato Market
  • Elite Author: Sold more than $75,000 on Envato Market
+6 more
ThemeBlvd says

This is one way to include the wp-load.php file as unisphere said. You’d just do something like this at the top of your style PHP file.

<?php //Setup location of WordPress
$absolute_path = __FILE__;
$path_to_file = explode( 'wp-content', $absolute_path );
$path_to_wp = $path_to_file[0];

//Access WordPress
require_once( $path_to_wp.'/wp-load.php' );

//Now continue with any WordPress suff...
?>

#your-custom-thing {
     color: #<?php echo get_option(‘color’); ?>;
}

415 posts
  • Has referred 10+ members
  • Has sold $250,000+ on Envato Market
  • Has collected 10+ items on Envato Market
  • Elite Author: Sold more than $75,000 on Envato Market
+5 more
unisphere says

Man those 3 first lines of code are much better than the way I’m doing it, hope you don’t mind I use them, they’re delicious :D

1028 posts
  • Has referred 500+ members
  • Has sold $500,000+ on Envato Market
  • Has collected 50+ items on Envato Market
  • Elite Author: Sold more than $75,000 on Envato Market
+6 more
ThemeBlvd says

Man those 3 first lines of code are much better than the way I’m doing it, hope you don’t mind I use them, they’re delicious :D

Have at it. :-) What are forums for, right?

by
by
by
by
by
by