Sunday, 11 October 2015

Wordpress Add multiple custom fields to the general settings page

Add multiple custom fields to the general settings page



function register_fields()
{
    register_setting('general', 'my_first_field', 'esc_attr');
    add_settings_field('my_first_field', '<label for="my_first_field">'.__('My Field' , 'my_first_field' ).'</label>' , 'print_custom_field', 'general');
}

function print_custom_field()
{
    $value = get_option( 'my_first_field', '' );
    echo '<input type="text" id="my_first_field" name="my_first_field" value="' . $value . '" />';
}

add_filter('admin_init', 'register_fields');

Function Reference/get settings
Reading a settings Value in wordpress
<h1><?php echo get_settings('blogname'); ?></h1> 

No comments:

Post a Comment