How can I add Media Selector to add_settings_field in WordPress?
This the extra fields I added to Settings -> General page in WordPress:
/**
* Add more input fields in general settings.
*/
add_action('admin_init', 'extended_general_settings');
function extended_general_settings() {
add_settings_section(
'other_site_details', // Section ID
'Other Site Details', // Section Title
'extended_general_settings_description_callback', // Callback
'general' // What Page? This makes the section show up on the General Settings Page
);
add_settings_field( // Content
'meta_description', // Option ID
'Meta Description', // Label
'extended_generals_setting_textarea_callback', // !important - This is where the args go!
'general', // Page it will be displayed (General Settings)
'other_site_details', // Name of our section
array( // The $args
'meta_description' // Should match Option ID
)
);
add_settings_field( // Keywords
'meta_keywords', // Option ID
'Meta Keywords', // Label
'extended_generals_setting_textarea_callback', // !important - This is where the args go!
'general', // Page it will be displayed (General Settings)
'other_site_details', // Name of our section
array( // The $args
'meta_keywords' // Should match Option ID
)
);
add_settings_field( // Telephone
'telephone', // Option ID
'Telephone', // Label
'extended_general_settings_textbox_callback', // !important - This is where the args go!
'general', // Page it will be displayed (General Settings)
'other_site_details', // Name of our section
array( // The $args
'telephone' // Should match Option ID
)
);
add_settings_field( // Email
'email', // Option ID
'Email', // Label
'extended_general_settings_textbox_callback', // !important - This is where the args go!
'general', // Page it will be displayed
'other_site_details', // Name of our section (General Settings)
array( // The $args
'email' // Should match Option ID
)
);
register_setting('general','meta_description', 'esc_attr');
register_setting('general','meta_keywords', 'esc_attr');
register_setting('general','telephone', 'esc_attr');
register_setting('general','email', 'esc_attr');
}
function extended_general_settings_description_callback() { // Section Callback
echo '<p>Add additional site info below here:</p>';
}
function extended_general_settings_textbox_callback($args) { // Textbox Callback
$option = get_option($args[0]);
echo '<input type="text" id="'. $args[0] .'" name="'. $args[0] .'" value="' . $option . '" class="regular-text ltr"/>';
}
function extended_generals_setting_textarea_callback($args) { // Textbox Callback
$option = get_option($args[0]);
echo '<textarea rows="6" cols="40" id="'. $args[0] .'" name="'. $args[0] .'" class="regular-text ltr">' . $option . '</textarea>';
}
But I want to add the media selector so that I can select an image from the media library where I have uploaded all my images to.
Is this possible?