Can't get options with $data['variable'].

(I'm use SMOF - Slightly Modded Options Framework)

For example in the header.php (index.php, footer.php, etc.):

global $data;
$logo_type = stripslashes( $data['type_logo'] );

and nothing happens, variable $logo_type contains nothing.

But if I use the same code in the \css\styles.php - all works fine. Code from \css\styles.php:


/* Background Body */ 
$bg_color = stripslashes ( $data['ct_bg_color'] );


/* Body BG Color */ 
body, .body-class { background-color: <?php echo $bg_color; ?> 

Function as part of framework :

/* Generate a static css file from the defined options
// This function will generate a static css file which you can use in your theme.
// Some examples of the dynamically generated options has been defined in css/styles.php
function generate_options_css($newdata) {

    $data = $newdata;   
    $css_dir = get_stylesheet_directory() . '/css/'; // Shorten code, save 1 call
    ob_start(); // Capture all output (output buffering)

    require($css_dir . 'styles.php'); // Generate CSS

    $css = ob_get_clean(); // Get generated CSS (output buffering)
    file_put_contents($css_dir . 'options.css', $css, LOCK_EX); // Save it


Link to Framework files: https://github.com/sy4mil/Options-Framework/tree/master/admin/functions

First encountered this problem... And can not understand what could be the problem (php, web hosting, etc.)

Anyone else encountered this problem?

  • 1
    Please post the relevant code from css/styles/php. – Chip Bennett Jan 21 '13 at 16:00
  • <?php /* Background Body */ $bg_color = stripslashes ( $data['ct_bg_color'] ); ?> /* Body BG Color */ body, .body-class { background-color: <?php echo $bg_color; ?> } – user771417 Jan 21 '13 at 23:32
  • Please add that as an edit to your question, rather than as a comment. :) Also: that doesn't have all of the relevant code. To wit: it doesn't include the code that defines $data. – Chip Bennett Jan 21 '13 at 23:35
  • It's all code, and it works :) PS: added to the start comment. – user771417 Jan 21 '13 at 23:37
  • Thanks for the question edit. It helps keep things cleaner, and easier to follow. :) But you've still not added the code from /css/styles.php that defines $data. It's in there, somewhere, in that file. – Chip Bennett Jan 21 '13 at 23:44

This is actually a PHP question, and not a WordPress question.

The issue is that global variables don't pass through the include()/require() call from the template file into header.php.

The solution is to define $data after you globalize it.

Without knowing your options framework or your Theme specifically, I can only answer in general terms; that said, you would likely define $data like so:

global $data;
$data = get_option( 'some_option' );


global $data;
$data = framework_get_options();

Hint: take a look at /css/styles.php to see how your framework/Theme does this, specifically.

| improve this answer | |
  • This framework works fine on the thousands websites. And I'm trying to understand what could be the problem. Unique situation. – user771417 Jan 22 '13 at 20:48

Maybe this help i use it...

Single Data:

<?php global $data; echo $data['your_option_id']; ?>

Conditional Data:

<?php global $data; ?>
<?php if($data['your_option_id']): ?>
   <?php echo $data['your_option_id']; ?>
<?php endif; ?>

Conditional Data with Default Data

<?php global $data; ?>
<?php if($data['your_option_id']): ?>
   <?php echo $data['your_option_id']; ?>
<?php else: ?>
   My Default Data
<?php endif; ?>
| improve this answer | |

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.