• Hi, i’m trying to add some custom theme options to my theme. I only want one custom theme option right now and that’s to control the page title of the home page with my custom post types on it

    In my functions.php I have the following

    add_action( 'admin_init', 'theme_options_init' );
    add_action( 'admin_menu', 'theme_options_add_page' ); 
    
    function theme_options_init(){
     register_setting( 'sample_options', 'sample_theme_options');
    } 
    
    function theme_options_add_page() {
     add_theme_page( __( 'Theme Options', 'sampletheme' ), __( 'Theme Options', 'sampletheme' ), 'edit_theme_options', 'theme_options', 'theme_options_do_page' );
    } 
    
    function theme_options_do_page() { global $select_options; if ( ! isset( $_REQUEST['settings-updated'] ) ) $_REQUEST['settings-updated'] = false; ?>
    <div>
    <?php screen_icon(); echo "<h2>". __( 'Custom Theme Options', 'customtheme' ) . "</h2>";
     if ( false !== $_REQUEST['settings-updated'] ) : ?>
    <div>
    <p><strong><?php _e( 'Options saved', 'customtheme' ); ?></strong></p></div>
    <?php endif; ?> 
    
    <form method="post" action="options.php">
    <?php settings_fields( 'sample_options' );  
    
     $options = get_option( 'sample_theme_options' ); ?>
     <table>
    
    <tr valign="top"><th scope="row">
    <?php _e( 'Specials Page Title', 'customtheme' ); ?></th>
    <td>
    <input id="sample_theme_options[special]" type="text" name="sample_theme_options[special]" value="<?php esc_attr_e( $options['special'] ); ?>" />
     </td>
    </tr> 
    
    </table> 
    
    <p>
    <input type="submit" value="<?php _e( 'Save Options', 'customtheme' ); ?>" />
    </p>
    </form>
    </div>
    <?php }
    
    in my header.php I put the following right before </head>
    <?php $options = get_option( 'sample_theme_options' ); ?>

    On my index.php I have the following above the loop as to not keep looping around with each post.

    <h1 class="entry-title"><?php echo $options['special']; ?></h1>

    In the dashboard, everything saves as it’s supposed to, but on the homepage, nothing shows up between the

    <h1 class="entry-title"></h1> tags.

    Can someone please advise? This is the first time i’ve created custom theme options within my theme.

  • The topic ‘Problems with custom theme options’ is closed to new replies.