Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9000359
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:18:06+00:00 2026-06-16T00:18:06+00:00

Two questions from a coding ub3r n00b… Firstly, I’m using the Options Framework Theme

  • 0

Two questions from a coding ub3r n00b…

Firstly, I’m using the Options Framework Theme by Devin Price and just wanting to know how would I output the background property in the <head> section of my header.php file, from the Theme Options page only if the user has uploaded an image or chosen a color for this?

My options.php:

$options[] = array(
    'name' =>  __('Background', 'options_framework_theme'),
    'desc' => __('Add a background.', 'options_framework_theme'),
    'id' => 'background-one',
    'std' => $background_defaults,
    'type' => 'background' );

My Theme Options page:

enter image description here

My header.php:

<style type="text/css">
<?php $background = of_get_option('background-one');
    echo 'body {';
        if ($background['color']) {   
        echo '
        background: ' .$background['color']. ';';
        }

        if ($background['image']) {
        echo '
        background: url('.$background['image']. ') ';
            echo ''.$background['repeat']. ' ';
            echo ''.$background['position']. ' ';
            echo ''.$background['attachment']. ';';
        } 
    echo '
    }';
?>
</style>

Which works perfectly fine in the front-end of my site, displaying the CSS as:

body {
    background: #8224e3;
    background: url(images/bg03.gif) repeat top left fixed;
}   

But if the user hasn’t chosen a colour or image as a background through the Theme Options page, the source code will output:

body {
}

How would I be able to remove the above CSS if the user hasn’t chosen a background?

From what I gather, an if statement needs to be created but I don’t how to write this up correctly as I’m fairly new to php.


Secondly, how would I be able to set a default background image in the framework?

My options.php:

// Background Defaults
    $background_defaults = array(
        'color' => '',
        'image' => '',
        'repeat' => 'no-repeat',
        'position' => 'top left',
        'attachment' => 'fixed' );

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T00:18:07+00:00Added an answer on June 16, 2026 at 12:18 am

    Just move a few things to be within an if statement, like so:

    <?php 
        $background = of_get_option('background-one');
        if ($background['color'] || $background['image']) {
            echo '<style type="text/css" >';
            echo 'body {';
            if ($background['color']) {   
                echo '
                background: ' .$background['color']. ';';
            }
    
            if ($background['image']) {
                echo '
                background: url('.$background['image']. ') ';
                echo ''.$background['repeat']. ' ';
                echo ''.$background['position']. ' ';
                echo ''.$background['attachment']. ';';
            } 
            echo '
            }';
            echo '</style>';
        }
    ?>
    

    And, for your second question, simply make the following change:

    // Set up a default image
    // NOTE: This is designed for the image to be located in your theme folder, inside an images folder
    $default = get_bloginfo("template_url") . 'images/default.jpg';
    // Background Defaults
    $background_defaults = array(
        'color' => '',
        'image' => $default,
        'repeat' => 'no-repeat',
        'position' => 'top left',
        'attachment' => 'fixed' );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two questions: From personal experience, what free blog engine is the best
Two questions: How can I import a file from a web address, without a
I have two questions. I want to send SMSes from a web-site in PHP
I have two questions regarding coding Haskell in Emacs/VIM in Linux : If one
This is sort of two coding style questions in one. I have a tab-dl'd
This question has two parts (maybe one solution?): Sample vectors from a sparse matrix
Question similar to this: select from two tables where linked column can be null
Two questions only: I have a website including a section of Blog in wordpress.
Two questions here, second is a little more complicated than first. 1 - I
Two questions, really: Is there a standard/convention regarding the placement on configuration files? For

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.