Saturday, 26 March 2016

How to Add New Field in General Settings Page? And how to use this Field's Value in WordPress Admin or Frontend.


1]  Add this below code in active theme's => functions.php file :-

$new_general_setting = new new_general_setting();

class new_general_setting {
    function new_general_setting( ) {
        add_filter( 'admin_init' , array( &$this , 'register_fields' ) );
    }
    function register_fields() {
        register_setting( 'general', 'favorite_color', 'esc_attr' );
        add_settings_field('fav_color', '<label for="favorite_color">'.__('Favorite Color?' , 'favorite_color' ).'</label>' , array(&$this, 'fields_html') , 'general' );
    }
    function fields_html() {
        $value = get_option( 'favorite_color', '' );
        echo '<input type="text" id="favorite_color" name="favorite_color" value="' . $value . '" />';
    }
}

2]  Add this below code where you want to display above Field's Value :-

echo $PriorityPoints = get_option( 'favorite_color' );  // Field Name

No comments:

Post a Comment