Чтобы вывести поле Advanced Custom Fields (ACF) на экране настроек администратора в WordPress, вам понадобится выполнить следующие шаги:
1. Убедитесь, что у вас установлен и активирован плагин Advanced Custom Fields (https://wordpress.org/plugins/advanced-custom-fields/). Если плагин уже активирован, пропустите этот шаг.
2. Создайте новое поле ACF или используйте уже существующее поле, в котором сохраняете нужную информацию. Например, вы можете создать поле my_custom_field
с типом 'text'.
3. Откройте файл functions.php
вашей темы (или создайте его, если его нет) и добавьте следующий код:
add_action('admin_menu', 'add_custom_acf_settings'); function add_custom_acf_settings() { add_options_page('Custom ACF Settings', 'Custom ACF Settings', 'manage_options', 'custom-acf-settings', 'render_custom_acf_settings'); } function render_custom_acf_settings() { ?> <div class="wrap"> <h1>Custom ACF Settings</h1> <form method="post" action="options.php"> <?php settings_fields('custom_acf_group'); do_settings_sections('custom-acf-settings'); submit_button(); ?> </form> </div> <?php }
4. Теперь вам нужно зарегистрировать настройки ACF. Добавьте следующий код в functions.php
перед закрывающим тегом ?>
:
add_action('admin_init', 'register_custom_acf_settings'); function register_custom_acf_settings() { register_setting('custom_acf_group', 'my_custom_field'); add_settings_section('custom_acf_section', 'Custom ACF Section', 'render_custom_acf_section', 'custom-acf-settings'); add_settings_field('my_custom_field', 'My Custom Field', 'render_my_custom_field', 'custom-acf-settings', 'custom_acf_section'); } function render_custom_acf_section() { echo 'This is a custom ACF section'; } function render_my_custom_field() { $value = get_option('my_custom_field'); echo '<input type="text" name="my_custom_field" value="' . esc_attr($value) . '" />'; }
5. сохраните изменения в файле functions.php
.
Теперь, когда вы зайдете на страницу настроек администратора WordPress (/wp-admin/options-general.php?page=custom-acf-settings
), вы увидите новую вкладку "Custom ACF Settings" с полем "My Custom Field". Введенное значение будет сохраняться и доступно для использования в вашей теме.
Надеюсь, этот подробный ответ поможет вам успешно вывести поле Advanced Custom Fields в настройках экрана администратора в WordPress.