I'm creating a theme option page and i try to display the values of two input in my front end :
function register_my_header() {
register_setting( 'header_options', 'header_options');
}
add_action('admin_init', 'register_my_header');
function add_header_settings() {
add_menu_page('Options header', 'Options header', 'manage_options', 'edit_header', 'header_edit_page', null, 58);
}
add_action('admin_menu', 'add_header_settings');
function header_edit_page() {
?>
<div id="theme-options-wrap">
<div class="icon32" id="icon-tools"> <br> </div>
<h2>Header Options</h2>
<p>Description</p>
<?php
if ( false !== $_REQUEST['updated'] ) : ?>
<div><p><strong><?php _e( 'Options saved' ); ?></strong></p></div>
<?php endif; ?>
<form method="post" action="options.php">
<?php settings_fields('header_options'); ?>
<?php $options = get_option('header_options'); ?>
<table class="form-table">
<tr>
<th scope="row">Mail</th>
<td>
<input type="text" name="header_options[txt_mail]" value="<?php echo $options['txt_mail']; ?>" />
</td>
</tr>
<tr>
<th scope="row">Phone number</th>
<td>
<input type="text" name="header_options[txt_number]" value="<?php echo $options['txt_number']; ?>" />
</td>
</tr>
</table>
<p class="submit">
<input type="submit" class="button-primary" value="<?php _e('Save Changes') ?>" />
</p>
</form>
</div>
<?php
}
function header_validate_options($input) {
$input['txt_mail'] = wp_filter_nohtml_kses($input['txt_mail']);
$input['txt_number'] = wp_filter_nohtml_kses($input['txt_number']);
return $input;
}
function header_add_content() {
$options = get_option('header_options');
}
add_filter("the_content", "header_add_content");
I'm able to save the value but when i call it with :
<div class="background-content"></div>
<div class="layout-header">
<h1 id='logo' class="image-logo">
<a href="<?php echo home_url(); ?>"><img <?php do_shortcode('[sitelogo]'); ?></a>
</h1>
<div id="contact">
<p>Contact Us</p>
<p><?php echo $options['txt_mail']; ?></p><p><?php echo $options['txt_number']; ?></p>
</div>
</div>
To display it in the front nothing happens ! What am i doing wrong ?
<p><?php echo $options['txt_number']; ?></p>
? In your code I can't see that piece of code.echo $options['txt_number'];
directly in a template file? Show us how are you doing that.$options
variable you set inheader_add_content()
function is not available outside the function neither in other files. That is the reason nothing happens with your code; if you turn on PHP notice errors on your server, you will get "Undefined variable" notice. You may need to learn about variables scope in PHP.