I'm trying to display a saved option of a url inside a text input on my themes' options page, but it's just simply not displaying. I've checked the database and my url is saved using the specified option name, I've tried simply echoing the option without escaping and I've also tried using the same esc_url() function outside of the add_settings_field() function and it does work there. The settings and sections are already registered as well. This leads me to believe I'm missing something stupidly obvious, or this may be a bug in the Settings API. Any help is appreciated, thanks.

function outputFavIcon(){ ?>
    <input class='uploadUrl' id='upload_fav' type='text' size='50' name='fp_smart_options[general_settings][fav_icon]' value="<?php esc_url($settings['general_settings']['fav_icon'],array('http','https')); ?>" />
    <input class='uploadButton' id="upload_fav_button" type="button" value="Upload Fav Icon" /><br />
    <span class='description'><?php _e('Enter a URL or upload an image for your fav icon. This should be 16 x 16 pixels'); ?>.</span>
    <?php if(isset($settings['generel_settings']['fav_icon'])){
        echo "<br /><img src='" . esc_url($settings['general_settings']['fav_icon'],array('http','https'),false) . "' width='16' height='16' />";
add_settings_field('fpFavIcon', 'Fav Icon', 'outputFavIcon', 'flexipress', 'fpUploadables');

1 Answer 1


I'm assuming $settings is an assigned variable elsewhere in your code?

If so, then ya gotta globalise it son (variable scope in PHP):

function outputFavIcon() {
    global $settings; ?>

And spell it right too ;)

<?php if ( isset ( $settings['generel_settings' /* <- typo? */]['fav_icon'] ) ) {
  • Yes it is though it's already been globalised after retrieving the options using get_option('fp_smart_options'); where 'fp_smart_options' is the sterilised array of theme options.
    – Ben
    Commented Aug 6, 2012 at 6:09
  • Global variables still need to be declared inside functions - read up on the linked documentation. Commented Aug 6, 2012 at 8:33
  • Ok, I've tried that but got no banana. I also tried re-globalising the array inside my callback function as you suggested and it's still not working.
    – Ben
    Commented Aug 6, 2012 at 18:19
  • You fix the typo too? Whatdya get when you print_r( $settings )? Commented Aug 7, 2012 at 0:19
  • Fixed it! The $settings needs to be globalised inside the validation function for some strange reason. I played about by moving the line of code around that globalises the $settings array and just suddenly decided to work. The typo had been fixed since you mentioned it yes, thanks and print_r($settings); was the function I mentioned in my original post that successfully outputted the settings as saved in the database.
    – Ben
    Commented Aug 7, 2012 at 18:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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