ThemeForest

WP dynamic stylesheet

1743 posts
  • Has been a member for 3-4 years
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
  • Exclusive Author
  • Sold between 5 000 and 10 000 dollars
  • Bought between 10 and 49 items
  • Germany
  • 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?

1 year ago
2389 posts Put a Donk On It
  • Has been a member for 2-3 years
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
  • Contributed a Tutorial to a Tuts+ Site
  • Interviewed on the Envato Notes blog
  • Beta Tester
  • Exclusive Author
  • Sold between 100 000 and 250 000 dollars
  • Elite Author
  • Bought between 10 and 49 items
  • United Kingdom
  • Referred between 50 and 99 users
ThemeProvince says

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

1 year ago
1743 posts
  • Has been a member for 3-4 years
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
  • Exclusive Author
  • Sold between 5 000 and 10 000 dollars
  • Bought between 10 and 49 items
  • Germany
  • 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 .

1 year ago
739 posts
  • Has been a member for 3-4 years
  • Exclusive Author
  • Sold between 10 000 and 50 000 dollars
  • Bought between 10 and 49 items
  • Ireland
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

1 year ago
798 posts
  • Has been a member for 2-3 years
  • Exclusive Author
  • Bought between 10 and 49 items
  • 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.

1 year ago
1743 posts
  • Has been a member for 3-4 years
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
  • Exclusive Author
  • Sold between 5 000 and 10 000 dollars
  • Bought between 10 and 49 items
  • Germany
  • 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.

1 year ago
407 posts
  • Has been a member for 3-4 years
  • Grew a moustache for the Envato Movember competition
  • Exclusive Author
  • Sold between 100 000 and 250 000 dollars
  • Elite Author
  • Bought between 1 and 9 items
  • Portugal
  • Referred between 10 and 49 users
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.

1 year ago
1008 posts
  • Has been a member for 3-4 years
  • Author had a File in an Envato Bundle
  • Exclusive Author
  • Sold between 250 000 and 1 000 000 dollars
  • Elite Author
  • Bought between 50 and 99 items
  • United States
  • Referred between 200 and 499 users
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’); ?>;
}

1 year ago
407 posts
  • Has been a member for 3-4 years
  • Grew a moustache for the Envato Movember competition
  • Exclusive Author
  • Sold between 100 000 and 250 000 dollars
  • Elite Author
  • Bought between 1 and 9 items
  • Portugal
  • Referred between 10 and 49 users
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

1 year ago
1008 posts
  • Has been a member for 3-4 years
  • Author had a File in an Envato Bundle
  • Exclusive Author
  • Sold between 250 000 and 1 000 000 dollars
  • Elite Author
  • Bought between 50 and 99 items
  • United States
  • Referred between 200 and 499 users
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?

1 year ago
by
by
by
by
by