147 posts
  • Has been part of the Envato Community for over 3 years
  • Has referred 10+ members
  • Has sold $250,000+ on Envato Market
  • Has collected 10+ items on Envato Market
+2 more
FlexiPress says

sorry, my bad code skill… :D updated!

we always try to make header.php as clean as possible… :D

so, we create separate file to output the custom css style using standard wordpress hook, and then include the file using include_once function at functions.php

that’s what we call “framework”... make it simple and clear for end user and make it easy for you to update… ;)

1141 posts
  • Has been part of the Envato Community for over 4 years
  • Has referred 1+ members
  • Has sold $40,000+ on Envato Market
  • Has collected 100+ items on Envato Market
+2 more
KarmaThemes says

Thanks Prima!

So I create several functions like this… Do I duplicate the whole part you gave me and just replace the function name or do I only duplicate the function itself inside the add_action? It will add lots of

echo '<style type="text/css">';
echo 'body { '.$bg_img.$bg_color.' }';
echo '</style>';
instances then in the output sourcecode, will it?

Sorry for being noobish :) Thanks!
147 posts
  • Has been part of the Envato Community for over 3 years
  • Has referred 10+ members
  • Has sold $250,000+ on Envato Market
  • Has collected 10+ items on Envato Market
+2 more
FlexiPress says

be creative, this is just for an example, you can replace prima_ prefix with yours.. :D

add_action('wp_head', 'prima_print_customstyles', 1000);
function prima_print_customstyles() {
    echo '<style type="text/css">';
    echo '/* Custom style output by PrimaThemes */';
    prima_print_background('body_background', 'body');
    prima_print_background('header_background', '#header');
    prima_print_background('content_background', '#content');
    prima_print_background('footer_background', '#footer');
    echo '</style>';
}
function prima_print_background( $option, $selector ) {
    $bg = of_get_option($option, false);
    if ($bg) {
        $bg_img = $bg['image'] ? 'background-image:url('.$bg['image'].') !important;' : ''; 
        $bg_color = $bg['color'] ? 'background-color:'.$bg['color'].' !important;' : ''; 
        if ($bg_img || $bg_color) {
            echo $selector.' { '.$bg_img.$bg_color.' }';
        }
    } 
}

so, by creating prima_print_background function, it makes the code more clean and re-usable… ;)

1141 posts
  • Has been part of the Envato Community for over 4 years
  • Has referred 1+ members
  • Has sold $40,000+ on Envato Market
  • Has collected 100+ items on Envato Market
+2 more
KarmaThemes says

Oh dear I think that’s too high for me… thank you so much for your help! I think in the end I will have to hire somebody to do this for me. PHP can do so much and it just won’t get in my head. :/

147 posts
  • Has been part of the Envato Community for over 3 years
  • Has referred 10+ members
  • Has sold $250,000+ on Envato Market
  • Has collected 10+ items on Envato Market
+2 more
FlexiPress says

Oh dear I think that’s too high for me… thank you so much for your help! I think in the end I will have to hire somebody to do this for me. PHP can do so much and it just won’t get in my head. :/

ohh, sorry to hear that… is it too difficult for you? you don’t need to use my code, you can do whatever that you think is simple… ;) I only give an example, the rest is yours…

you are welcome, we all know that learning need process… i am happy to help here… ;)

1141 posts
  • Has been part of the Envato Community for over 4 years
  • Has referred 1+ members
  • Has sold $40,000+ on Envato Market
  • Has collected 100+ items on Envato Market
+2 more
KarmaThemes says

No, your code is great and it does make perfectly sense. But I guess as soon as I need to change anything else than the background color I’m stuck again :/ Would you be up for work like that?

And: could you by any chance tell me how I can set a default fallback for these settings? So the default background images get used if nothing is set in the options. (Figured it out, disregard the last one)

by
by
by
by
by
by