0

so I am trying t add some admin menu's to a theme file. I have followed the examples and documentation from the codex and almost have things working, but I've run into a little problem when trying to add multiple (sub) pages.

Everything seems to work fine if I have a single admin page, but when I add the function to create a sub admin page I am no longer able to save either. When I do try to save I get the following error message:

Warning: Cannot modify header information - headers already sent by (output started at /home/site/public_html/development/base-theme/wp-content/themes/wordpress-theme/admin/setting_pages.php:75) in /home/site/public_html/development/base-theme/wp-includes/pluggable.php on line 1196

In my functions.php file I am calling in another php file which contains the following code:

<?php 

    /*****************************************************
            Create Website & Theme Options
    *****************************************************/
    // create individual settings pages
    add_action("admin_menu", "setup_theme_admin_menus");

    function setup_theme_admin_menus() {
        add_menu_page('Website Settings', 'Website Settings', 'manage_options', 'website-settings', 'website_settings');
        add_submenu_page( 'website-settings', 'Layout Options', 'Layout', 'manage_options', 'layout-options', 'layout_options');

        add_action( 'admin_init', 'register_website_settings_options' );
    }


    function register_website_settings_options() {
        register_setting( 'website_settings-group', 'new_option_name' );
        register_setting( 'website_settings-group', 'second_option_name' );
    }


    /*****************
    Page saved message
    ******************/
    function page_saved(){
        if( isset($_GET['settings-updated']) ) { ?>
        <div id="message" class="updated">
            <p><strong><?php _e('Settings saved.') ?></strong></p>
        </div>
    <?php } //end if
    }



    /******************************
        Page: Website Settings
    ******************************/
    function website_settings() {
    ?>
    <div class="wrap">
    <?php page_saved(); ?>
    <h2>Website Settings</h2>

    <form method="post" action="options.php">
        <?php settings_fields( 'website_settings-group' ); ?>
        <?php do_settings_sections( 'website_settings-group' ); ?>
        <table class="form-table">
            <tr valign="top">
            <th scope="row">New Option Name</th>
            <td><input type="text" name="new_option_name" value="<?php echo esc_attr( get_option('new_option_name') ); ?>" /></td>
            </tr>
        </table>

        <?php submit_button(); ?>

    </form>
    </div> <? }

    ?>



    <?php 
    /******************************
        Page: Layout Settings
    ******************************/
    function layout_options() {
    ?>
    <div class="wrap">
    <?php page_saved(); ?>
    <h2>Layout Options</h2>

    <form method="post" action="options.php">
        <?php settings_fields( 'website_settings-group' ); ?>
        <?php do_settings_sections( 'website_settings-group' ); ?>
        <table class="form-table">
            <tr valign="top">
            <th scope="row">Second Option Name</th>
            <td><input type="text" name="second_option_name" value="<?php echo esc_attr( get_option('second_option_name') ); ?>" /></td>
            </tr>
        </table>

        <?php submit_button(); ?>

    </form>
    </div> <? }

    ?>

Can anyone help?

  • Please try with removing blank white space between php tags. for example line # 60-64 – Vee Jul 10 '15 at 11:54
  • Wow, I think that did the trick - what's the issue with spaces? – Kev Jul 10 '15 at 13:28
  • 2
    Spaces are characters. If you send a character too soon you will get this error. Often, a space after the closing ?> is the culprit. Best practices are to simple not have a closing (very last) ?>. – s_ha_dum Jul 10 '15 at 15:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.