Ready to get started?Download WordPress


Theme Option Page - register_setting (5 posts)

  1. simplyworks
    Posted 3 years ago #

    I'm updating a option page for my theme to use settings_fields and post to options.php

    The code works and the option is save to the wp_options table, but I do not get a confirmation message back.
    Example: <div id="message" class="updated">Setting Saved</div>

    Here is the code:

    function swc_form_init ()
    	register_setting('swc_form_options', 'swc_theme_color_selection', );
    //  theme color options
    function swc_theme_color_page() {
    <div class="wrap"><?php screen_icon(); ?>
    <h2>Theme Color</h2>
    <form action="options.php" method="post" id="swc-theme-color-form">
    <?php settings_fields('swc_form_options');  ?>
    <h3><label for="swc_theme_color_selection">Enter you color option</label>
    <input type="text" id="swc_theme_color_selection" name="swc_theme_color_selection" value="<?php echo esc_attr(get_option('swc_theme_color_selection')); ?>" /></h3>
    <p><input type="submit" name="submit" value="Save Selection" /></p>
  2. esmi
    Forum Moderator
    Posted 3 years ago #


    <div class="wrap"><?php screen_icon(); ?>
    <h2>Theme Color</h2>
    <?php if ( false !== $_REQUEST['updated'] ) : ?>
    <div class="updated fade"><p><strong><?php _e( 'Your theme options have been saved',); ?></strong></p></div>
    <?php endif; ?>
  3. simplyworks
    Posted 3 years ago #

    Thanks esmi,

    I made a slight change once I notice the returning url sends a "updated=true" in the string.

    here is the code that worked for me:

    <div class="wrap"><?php screen_icon(); ?>
    <h2>Theme Color</h2
    <?php if (isset($_GET['updated']) && ($_GET['updated'] == 'true') ) : ?>
    <div class="updated fade"><p><strong><?php _e('Your theme options have been saved'); ?></strong></p></div>
    <?php endif; ?>

    I guess what threw me for a loop, was the fact that if I write this as plugin and not theme option page (the same code) returns a saved message.

    thanks again for the coding tip!

  4. esmi
    Forum Moderator
    Posted 3 years ago #

    No problem :-)

  5. czone
    Posted 3 years ago #

    I used different codes then above to create a custom page for my theme. It works fine, saves data in wp-options table at Database and shows confirm msg as well.

    When i call (echo) the text contents into the page, it shows blank.

    Can anyone help me pls?

Topic Closed

This topic has been closed to new replies.

About this Topic