How to add Custom Field in WordPress Admin Settings Page

In this article I am going to explain how to add a custom fiend in WordPress admin settings page. WordPress has many actions and filters those makes it flexible to customize or add any new features.

A custom setting field can be added by using add_settings_field function in WordPress.

That can be called in the admin_init action.

Let’s see an example that explains about how to add custom setting.

In the below example I will add a blog title field in the WordPress admin settings page.


add_action('admin_init', 'child_settings_api_init');
function child_settings_api_init() {
    add_settings_field(
            'child_blogtitle', 'Blog Page Title', 'blog_page_title_callback', 'reading'
    );
    register_setting('reading', ' child_blogtitle');
}
function blog_page_title_callback() {
echo '<input type="text" class="regular-text" name=" child_blogtitle" value="' . get_option('child_blogtitle') . '" />';
}

To know more about the add_settings_field function please refer to this link https://codex.wordpress.org/Function_Reference/add_settings_field

Hope this helps.

Share this Post