Skip to content

Instantly share code, notes, and snippets.

@mohnatus
Created April 9, 2020 11:37
Show Gist options
  • Select an option

  • Save mohnatus/fe796f4ffbdb283726a1b568e27a3db7 to your computer and use it in GitHub Desktop.

Select an option

Save mohnatus/fe796f4ffbdb283726a1b568e27a3db7 to your computer and use it in GitHub Desktop.
<?php
add_action('admin_init', 'add_options_section');
function add_options_section() {
add_settins_section(
'section_name',
'Section Title',
'section_callback',
'reading'
);
add_settings_field(
'field_name',
'Field Label',
'field_callback',
'reading',
'section_name'
);
register_setting('reading', 'option_name', 'strip_tags');
}
function section_callback() {
echo 'Some message before options fields';
}
function field_callback() {
$option = get_option('option_name');
?>
<input name='option_name' value='<?= $option ?>'>
<?php
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment