Hello readers today we will discuss "How to create custom setting in wordpress admin dashboard".
Open your function.php file and write the below code:-
/**
* Sound promo code
 */
add_action( 'admin_menu', 'showMenu' );
function showMenu() {   
    add_menu_page('promo_code_setting', 'Sound Promo Code', 'administrator', 'promo_code_setting', 'promo_code_setting', 'dashicons-admin-generic', '25.2');
    // Call register settings function
    add_action( 'admin_init', 'register_my_setting' );
}
//Register Custom setting variable
function register_my_setting() {
    register_setting( 'sound_promo_code', 'promo_code' );
} 
//add new menu in the admin dashboard area
function promo_code_setting() {
    if ( !current_user_can( 'administrator' ) ) {
        wp_die( __( 'You do not have sufficient permissions to access this page.' ) );
    }    ?>
    <div class="wrap">
        <h2>Sound Promo Code</h2>
        <form method="post" action="options.php">
            <?php settings_fields( 'sound_promo_code' ); ?>
            <?php do_settings_sections( 'sound_promo_code' ); ?>
            <table class="form-table">
                <tr valign="top">
                    <th scope="row">Sound Promo Code: </th>
                    <td>
                        <input type="text" name="promo_code" value="<?php echo get_option('promo_code'); ?>" placeholder="Promo Code" style="width:65%;" />
                    </td>
                </tr>
            </table>
            <table class="form-table">
                <tr valign="top">
                    <th scope="row"></th>
                    <td>
                        <?php submit_button(); ?>
                    </td>
                </tr>
            </table>
        </form>
    </div>
    <?php
}
                       
                    
0 Comment(s)