Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End Default color in style.php

  • This topic is empty.
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #180321
    daku
    Participant

    Hi friends I used your tutorial here https://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

    #180343
    shaneisme
    Participant

    Maybe try something like this:

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

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

    #180344
    burr
    Participant

    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.

    #180345
    __
    Participant

    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)
  • The forum ‘Back End’ is closed to new topics and replies.