get_options isn't returning a value when used inside sidebar.php (3 posts)

  1. gotlisch
    Posted 1 year ago #

    Hi there, have come across a strange problem, I'm unable to return and display one of my theme options when I try to call get_options() from within my sidebar.php file.

    I've tried to call the same option from other page templates such as index.php, header.php etc and it works perfectly fine but as soon as I call the option from the sidebar file I get nothing...no idea what's going on here.

    This is the code I'm using...like I said the option is definetly being stored properly cause i'm able to access it perfectly fine from other parts of my theme.

    <div id="sidebar">		     
                <?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('Sidebar') ) : ?>        
                    <div class="side_box">
    				<? if(get_field('google-maps'))	{?>
    				<h3><? echo get_option($shortname.'_google_maps_heading',''); ?></h3>				
    				<iframe src="<? echo get_field('google-maps') ?>" width="300" height="250" frameborder="0" style="border:0"></iframe>						
                <?php endif; ?>        

    Thanks in advance for your help!!


  2. Steven Jones
    Posted 1 year ago #

    It looks like you're expecting $shortname to be populated with some data, but it's going to be empty unless it's a global variable.

    If you have used $shortname in your main script that calls the sidebar then you need to populate it again in sidebar.php

  3. gotlisch
    Posted 1 year ago #

    Hi Steven, $shortname is a global varible...it's just being used as a prefix to make sure my global varibles don't conflict with any other ones.. this is how it's been setup in the settings.php file:

    $themename = "Simple Grid";
    $shortname = "simple_grid";
    $settings_list = array(
        'pinterest_link',		'home_page_title',
    /*function add_homestead_scripts() {
    //  wp_enqueue_script('homestead-settings1', WP_CONTENT_URL.'/themes/homestead/jquery.js');
      wp_enqueue_script('homestead-settings2', WP_CONTENT_URL.'/themes/homestead/jquery-1.4.2.min.js');
      wp_enqueue_script('homestead-settings3', WP_CONTENT_URL.'/themes/homestead/jpicker-1.1.3.min.js');
      //wp_enqueue_script('homestead-settings1', WP_CONTENT_URL.'/themes/homestead/css/colorpicker.css');
    function mytheme_add_admin() {
        global $themename, $shortname, $settings_list;
        if ( $_GET['page'] == basename(__FILE__) ) {
            if ( 'save' == $_REQUEST['action'] ) {
                      foreach($settings_list as $value) {
                        //echo '<script type="text/javascript">alert("' . $value . '");</script>';
                        //if($_REQUEST[$value] != "")
                          //update_option($shortname . '_' . $value,$_REQUEST[$value]);
                          update_option($shortname . '_' . $value,mysql_real_escape_string($_REQUEST[$value]));
                      header("Location: themes.php?page=settings.php&saved=true");
        add_theme_page($themename." Settings", $themename." Settings", 'edit_themes', basename(__FILE__), 'mytheme_admin');
    function mytheme_admin() {
        global $themename, $shortname, $settings_list;
        if ( $_REQUEST['saved'] ) echo '<div id="message" class="updated fade"><p><strong>'.$themename.' settings saved.</strong></p></div>';
        if ( $_REQUEST['reset'] ) echo '<div id="message" class="updated fade"><p><strong>'.$themename.' settings reset.</strong></p></div>';
    <style type="text/css">
    table { border: none; }
    td { padding: 5px; }
    .ss_text { width: 350px; }
    <div class="wrap">
    <h2><?php echo $themename; ?> Theme Options</h2>
    <form method="post">
    <td>Home Page Heading ln1:</td>
    <td><input type="text" name="home_page_heading_ln1" class="ss_text" value="<?php echo stripslashes(stripslashes(get_option($shortname.'_home_page_heading_ln1',''))); ?>" /></td></tr>

Topic Closed

This topic has been closed to new replies.

About this Topic