1799 posts
  • Has been a member for 5-6 years
  • Germany
  • Exclusive Author
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
  • Sold between 5 000 and 10 000 dollars
  • Microlancer Beta Tester
  • Bought between 10 and 49 items
  • Referred between 1 and 9 users
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?

2509 posts Put a Donk On It
  • Exclusive Author
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
  • Elite Author
  • Sold between 250 000 and 1 000 000 dollars
  • Attended a Community Meetup
  • Referred between 100 and 199 users
  • Contributed a Tutorial to a Tuts+ Site
+5 more
ThemeProvince says

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

1799 posts
  • Has been a member for 5-6 years
  • Germany
  • Exclusive Author
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
  • Sold between 5 000 and 10 000 dollars
  • Microlancer Beta Tester
  • Bought between 10 and 49 items
  • Referred between 1 and 9 users
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
  • Bought between 100 and 499 items
  • Exclusive Author
  • Has been a member for 5-6 years
  • Ireland
  • Sold between 10 000 and 50 000 dollars
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

1026 posts
  • Referred between 1 and 9 users
  • Sold between 1 000 and 5 000 dollars
  • Has been a member for 4-5 years
  • Bought between 10 and 49 items
  • Exclusive Author
  • Microlancer Beta Tester
  • United States
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 been a member for 5-6 years
  • Germany
  • Exclusive Author
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
  • Sold between 5 000 and 10 000 dollars
  • Microlancer Beta Tester
  • Bought between 10 and 49 items
  • Referred between 1 and 9 users
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
  • Elite Author
  • Sold between 250 000 and 1 000 000 dollars
  • Has been a member for 4-5 years
  • Exclusive Author
  • Grew a moustache for the Envato Movember competition
  • Bought between 10 and 49 items
  • Referred between 10 and 49 users
  • Portugal
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
  • Elite Author
  • Sold between 250 000 and 1 000 000 dollars
  • Author had a File in an Envato Bundle
  • Bought between 50 and 99 items
  • Exclusive Author
  • Has been a member for 4-5 years
  • Referred between 500 and 999 users
+1 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
  • Elite Author
  • Sold between 250 000 and 1 000 000 dollars
  • Has been a member for 4-5 years
  • Exclusive Author
  • Grew a moustache for the Envato Movember competition
  • Bought between 10 and 49 items
  • Referred between 10 and 49 users
  • Portugal
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
  • Elite Author
  • Sold between 250 000 and 1 000 000 dollars
  • Author had a File in an Envato Bundle
  • Bought between 50 and 99 items
  • Exclusive Author
  • Has been a member for 4-5 years
  • Referred between 500 and 999 users
+1 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