0

I am using the Options Framework to give the theme user the ability to upload their own background image.

I have an image upload option with option ID = page_background.

In header.php, I have:

<?php if (of_get_option('page_background', 'no entry')) { ?>
<style>
body {
 background: url(<?php echo of_get_option('page_background', 'no entry');?>) no-repeat center center fixed;
    -webkit-background-size: cover;
    -moz-background-size: cover;
    -o-background-size: cover;
    background-size: cover;
}
</style>
<?php } else { ?>
<style>
body {
 background: url(<?php echo get_template_directory_uri(); ?>/images/bodybg.jpg) no-repeat center center fixed;
    -webkit-background-size: cover;
    -moz-background-size: cover;
    -o-background-size: cover;
    background-size: cover;
}
</style>
<?php } ?>

At present, there is no background image uploaded, so the IF statement should return false, and proceed to the ELSE section, where a predefined background image is applied.

However, the front end returns code: background: url(no entry)

I use this exact same code on another theme and it works.

Any ideas what is wrong with this theme?

0

You're forcing of_get_option to return a value in all cases, by setting the 2nd argument, which is the default value to return in the case the option doesn't exist. If you want it to evaluate to false in the case where there is no value, remove the 2nd argument:

if (of_get_option('page_background')){

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.