2158 posts
  • Elite Author
  • Sold between 250 000 and 1 000 000 dollars
  • Exclusive Author
  • Community Moderator
  • Bought between 50 and 99 items
  • Referred between 200 and 499 users
  • Has been a member for 5-6 years
  • Won a Competition
+10 more
mpc Volunteer moderator says

Hi guys, I am looking for some nice way to print styles with php variables, most of you use something like Theme Options Framework so you know what I mean (ex: you have a color value stored in the Theme Option Panel and you want to pass to it CSS ). The one way is to just print the styles section into WP header but I guess this is not very nice way… So the other way I found it this http://css-tricks.com/css-variables-with-php/ but for this to work we need to include wp-load.php and because there is problem locating this file I came across a lot of articles saying “DO NOT IMPORT WP -LOAD”. So my question is how do you do this? :)

2429 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

Here’s how I did it in a free theme:

Using the regular style.css for most CSS . Then, for styles that can be set from theme options:

In functions.php:


add_filter('query_vars', 'csp_new_var');
function csp_new_var($public_query_vars) {
    $public_query_vars[] = 'csp_style';
    return $public_query_vars;
}

add_action('template_redirect', 'csp_css_display');
function csp_css_display(){
    $css = get_query_var('csp_style');
    if ($css == 'css'){
        include_once (TEMPLATEPATH . '/cspstyle.php');
        exit;  //This stops WP from loading any further
    }
}

In header.php

<link href="&lt;?php bloginfo('url'); ?&gt;/?csp_style=css" rel="stylesheet" media="all" type="text/css" />

Now, here’s a part of cspstyle.php (I’m using the Option Framework) :


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

<?php $bgimage[] = of_get_option('csp_bg_images'); // create an array with the repeating pattern backgrounds
    $imagepath =  get_bloginfo('stylesheet_directory') . '/images/'; // path to theme images folder
    $custombg = of_get_option('csp_custom_background'); // get the custom background value(s)
?>

body{
    color: #e9e2ee;
    font-size: 14px;
    background: <?php if ($custombg) { // user specified custom bg ?> use that! ?>
                    <?php echo $custombg['color']; ?>
                    <?php if ($custombg['image']) {?> url("<?php echo $custombg['image'] ?>");  
                <?php } else { //defaults ?> bgcolor and pixel pattern ?>      

                    <?php echo of_get_option('csp_bgcolor'); ?> 
                    url("<?php echo $imagepath."".$bgimage[0]; ?>.png");
                <?php } } ?>

}

Forum screwed my code a little, but I’m sure you understand.

97 posts
  • Bought between 10 and 49 items
  • Elite Author
  • Exclusive Author
  • Finland
  • Has been a member for 5-6 years
  • Referred between 100 and 199 users
  • Sold between 250 000 and 1 000 000 dollars
Smuliii says

I used this method in my latest theme: WP dynamic stylesheet | ThemeForest Community Forums

3007 posts
  • Author had a File in an Envato Bundle
  • Bought between 1 and 9 items
  • Elite Author
  • Europe
  • Exclusive Author
  • Has been a member for 3-4 years
  • Referred between 100 and 199 users
+2 more
duotive says

I really recommend you do not do this. We do this and we will quit it. Just add the css with a function in the theme’s header and not call a php file. It adds support requests and slows the whole theme down.

741 posts
  • Has been a member for 5-6 years
  • Sold between 50 000 and 100 000 dollars
  • Exclusive Author
  • Most Wanted Bounty Winner
  • Bought between 50 and 99 items
  • Poland
  • Referred between 10 and 49 users
Orbital_Themes says
duotive said
I really recommend you do not do this. We do this and we will quit it. Just add the css with a function in the theme’s header and not call a php file. It adds support requests and slows the whole theme down.

Can you elaborate?

3007 posts
  • Author had a File in an Envato Bundle
  • Bought between 1 and 9 items
  • Elite Author
  • Europe
  • Exclusive Author
  • Has been a member for 3-4 years
  • Referred between 100 and 199 users
+2 more
duotive says
pogoking said
duotive said
I really recommend you do not do this. We do this and we will quit it. Just add the css with a function in the theme’s header and not call a php file. It adds support requests and slows the whole theme down.
Can you elaborate?

Like what? Ask me please. I do not know what to elaborate more.

211 posts
  • Has been a member for 5-6 years
  • Bought between 50 and 99 items
  • Referred between 1 and 9 users
  • Exclusive Author
agusmu says
duotive said
I really recommend you do not do this. We do this and we will quit it. Just add the css with a function in the theme’s header and not call a php file. It adds support requests and slows the whole theme down.

+1000

we also removed dynamic style php file from our theme last month because of performance issue, you can use tools.pingdom.com to test the load time and compare it…

adding styles directly to your header using wp_head hook is better option for faster website load time.

741 posts
  • Has been a member for 5-6 years
  • Sold between 50 000 and 100 000 dollars
  • Exclusive Author
  • Most Wanted Bounty Winner
  • Bought between 50 and 99 items
  • Poland
  • Referred between 10 and 49 users
Orbital_Themes says

What are the support requests about? What kind of problems do your buyers have with this method? And regarding slowing down – you mean that it takes too much time to load WP manually or too many database requests to get every single option?

3007 posts
  • Author had a File in an Envato Bundle
  • Bought between 1 and 9 items
  • Elite Author
  • Europe
  • Exclusive Author
  • Has been a member for 3-4 years
  • Referred between 100 and 199 users
+2 more
duotive says
pogoking said
What are the support requests about? What kind of problems do your buyers have with this method? And regarding slowing down – you mean that it takes too much time to load WP manually or too many database requests to get every single option?
Buyes have issues with server configurations. If folders leading to public_html have 777 permission set the dinamic php stylesheets will not work and give a 500 internal server error. For the slow down, most customers have a shared host and shared hosts do not really like having requests to php files after the website draw has finished. I mean the server outputs the dom and then it needs to execute another php file. It slows them down a lot.
2158 posts
  • Elite Author
  • Sold between 250 000 and 1 000 000 dollars
  • Exclusive Author
  • Community Moderator
  • Bought between 50 and 99 items
  • Referred between 200 and 499 users
  • Has been a member for 5-6 years
  • Won a Competition
+10 more
mpc Volunteer moderator says

So it is better to place the “custom” css in the Header with add_action(‘wp_head’, ‘add_my_head’); ?

by
by
by
by
by
by