Grow your CSS skills. Land your dream job.

Default color in style.php

  • # August 22, 2014 at 2:58 pm

    Hi friends I used your tutorial here http://css-tricks.com/css-variables-with-php/
    It works I have something like that

    <?php
    header(“Content-type: text/css; charset: UTF-8″);
    $absolute_path = explode(‘wp-content’, $_SERVER['SCRIPT_FILENAME']);
    $wp_load = $absolute_path[0] . ‘wp-load.php';
    require_once($wp_load);
    $bg1 = of_get_option(‘menubg’);
    $bg2 = of_get_option(‘contentbg’);
    /**
    Do stuff like connect to WP database and grab user set values
    */

    header(‘Content-type: text/css’);
    header(‘Cache-control: must-revalidate’);
    ?>
    .menu {
    background:<?php echo $bg1; ?>;
    }
    .content {
    background:<?php echo $bg2; ?>;
    }

    But I want to set a default color if nothing selected in theme settings page and I tried this one but didnt work.

    <?php if(!empty($bg2)) { echo $bg2; } else { echo “#000″; } ?>

    Please can you help me? The comments were closed thankyou

    # August 22, 2014 at 5:40 pm

    Maybe try something like this:

    print (isset($bg2)) ? $bg2 : '#000';

    I’m not 100% sure what of_get_option is returning though.

    # August 22, 2014 at 5:50 pm

    Too me it seems like a lot of bloat to achieve what you are trying to do.

    Maybe you could set a default color in your css file, then override it with an inline style in your php if an option is selected.

    __
    # August 22, 2014 at 6:30 pm

    If this function is from the wordpress options framework plugin, note that the function signature looks like:

    of_get_option($id,$default);
    

    …which implies (I haven’t checked) that you can simply pass a default value when you call the function in the first place.

    $bg2 = of_get_option( 'contentbg','#000' );
    
Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".