Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have a theme for which I am able to retrieve The theme options on the header.php file by declaring a global variable and save the options in a variable.

<?php
global $options_name;
$options = get_option($options_name);
//$options returns the theme options when called on header.php but an empty array on index.php

?>

I am returned an empty array when I declare the same global variable and store the options in a variable in index.php of the theme files.

How can I retrieve the theme options in index.php file, as it works fine in header.php?

here is the header.php file:

<?php global $option_name; 
$options = get_option($option_name);
?>
<!DOCTYPE PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US" xml:lang="en-US" prefix="og: http://ogp.me/ns# fb: http://ogp.me/ns/fb#" >
    <head>
        <meta charset="<?php bloginfo('charset'); ?>" />
        <meta name="viewport" content="width=device-width" />
        <title><?php
    /*
     * Print the <title> tag based on what is being viewed.
     */
    global $page, $paged;

    wp_title( '|', true, 'right' );

    // Add the blog name.
    bloginfo( 'name' );

    // Add the blog description for the home/front page.
    $site_description = get_bloginfo( 'description', 'display' );
    if ( $site_description && ( is_home() || is_front_page() ) )
        echo " | $site_description";

    // Add a page number if necessary:
    if ( $paged >= 2 || $page >= 2 )
        echo ' | ' . sprintf( __( 'Page %s', 'PuraVida' ), max( $paged, $page ) );

    ?></title>
        <link rel="stylesheet" type="text/css" href="<?php bloginfo('template_directory'); ?>/style.css" />
        <link href='http://fonts.googleapis.com/css?family=Oswald:400,700' rel='stylesheet' type='text/css'>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>                
       <script src="<?php bloginfo('template_directory'); ?>/js/jquery-dropdown.js"></script>


   <?php wp_head(); ?>
    </head>
    <body <?php body_class(); ?>>
        <header class="wrap">
            <div class="logoarea">
                <a href="<?php bloginfo('wpurl'); ?>"><img src="<?php echo $options["logo"]; ?>" /></a>
            </div>
            <div class="navmenu">
                <?php wp_nav_menu( array( 'container_class' => 'menu-header', 'theme_location' => 'primary', 'fallback_cb' => FALSE ) ) ?>
            </div>

        </header>

And Here is the index.php file:

<?php get_header(); ?>

<?php get_sidebar(); ?>

        <div class="clear"></div>
        <?php get_footer(); ?>
share|improve this question
    
Can you show us both header.php and index.php where you are retrieving theme option? –  Vinod Dalvi Sep 6 '13 at 5:21
    
@VinodDalvi It is a normal header.php and index.php file that a theme has, but the weird thing is that theme options are being retrieved in header.php file but it isnt working for index.php file, I have tried re-declaring the global variable $options_name in index.php but no luck –  Mark Sep 6 '13 at 5:25
    
@Marh that's why i am asking you to show me code so that i can troubleshoot it. –  Vinod Dalvi Sep 6 '13 at 5:26
    
@VinodDalvi Alright I have updated the question with codes that I have in header.php and index.php –  Mark Sep 6 '13 at 5:32
    
How are you accessing it in index.php file? Have you tried doing global $options_name; echo $options_name; in index.php file? What's your $options_name? Are you replacing it with your real $options_name? –  Vinod Dalvi Sep 6 '13 at 5:39

1 Answer 1

up vote 0 down vote accepted

Try passing 'my_theme_options' directly to get_option() function instead of storing it in variable as following.

$options = get_option('my_theme_options');

Instead of

global $option_name; 
$options = get_option($option_name);
share|improve this answer
    
thanks, it worked –  Mark Sep 6 '13 at 8:00

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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