Skip to content

Instantly share code, notes, and snippets.

@tananin
Last active July 31, 2021 08:51
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tananin/37c7e47ae0442071414a102cf9f05e72 to your computer and use it in GitHub Desktop.
Save tananin/37c7e47ae0442071414a102cf9f05e72 to your computer and use it in GitHub Desktop.
<?php
// Carbon Fields. Theme options.
require get_theme_file_path() . '/inc/carbonfields.php';
// Carbon Fields Gutenberg bloks.
require get_theme_file_path() . '/inc/carbonblocks.php';

Carbon Fields

Краткая инструкция

  1. Скачать и установить zip архив плагина
  2. Создать в теме папку inc
  3. Создадим файл настройки темы **inc/carbonfields.php
  4. Создадим папку inc/carbonblocks
  5. Создадим файл блоков inc/carbonblocks.php
  6. Подключить в файле functions.php через require()

Страница настроек темы

Для создания страницы настроек используем Carbon fields

Минимально необходимое:

<?php
use Carbon_Fields\Container;
use Carbon_Fields\Field;

/**
 * Включение Carbon Fields
 */
function crb_load() {
    \Carbon_Fields\Carbon_Fields::boot();
}
add_action( 'after_setup_theme', 'crb_load' );

/**
 * Задаём поля
 */

function crb_attach_theme_options() {
    Container::make( 'theme_options', 'Найстройки сайта' )
        ->add_fields(
            array(
                Field::make( 'text', 'author_name',  'Имя автора' )
            )
        );
}
add_action( 'carbon_fields_register_fields', 'crb_attach_theme_options' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment