Customizer Settings and fields

Support MB Settings Page Customizer Settings and fields

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #48180
    webdevwebdev
    Participant

    Hi,
    I've set up a customizer section using MB Settings and using the following code:

    add_filter( 'mb_settings_pages', 'wcpp_masthead_text' );
    
    function wcpp_masthead_text( $settings_pages ) {
    	$settings_pages[] = [
            'menu_title'      => __( 'Homepage Intro', 'wcpp' ),
            'id'              => 'homepage-masthead-text',
            'capability'      => 'edit_published_pages',
            'option_name'   => 'theme_mods_masthead_text',
            'style'           => 'no-boxes',
            'columns'         => 1,
            'customizer'      => true,
            'customizer_only' => true,
            'network'         => false,
        ];
    
    	return $settings_pages;
    }
    
    add_filter( 'rwmb_meta_boxes', 'wcpp_masthead_field' );
    
    function wcpp_masthead_field( $meta_boxes ) {
        $prefix = '';
    
        $meta_boxes[] = [
            'title'          => __( 'Homepage Intro Text', 'wcpp' ),
            'id'             => 'homepage-masthead-wysiwyg',
            'settings_pages' => ['homepage-masthead-text'],
            'fields'         => [
                [
                    'name'              => __( 'Masthead Text', 'wcpp' ),
                    'id'                => $prefix . 'masthead_text',
                    'type'              => 'wysiwyg',
                    'raw'               => false,
                    'required'          => false,
                    'clone'             => false,
                    'hide_from_rest'    => false,
                    'hide_from_front'   => false,
                    'limit'             => 150,
                        'wpautop' => false,
                    'limit_type'        => 'character',
                    'options'         => [
                        'media_buttons' => true,
                        'teeny'         => false,
                        'tinymce'       => [
                            'toolbar1' => 'bold,italic,underline,|,bullist,numlist,|,link,unlink',
                            'toolbar2' => '',
                            'toolbar3' => '',
                            'toolbar4' => '',
                            'toolbar5' => '',
                            'wpautop' => false,
                        ],
                        'quicktags'    => false,
                    ],
                ],
            ],
        ];
    
        return $meta_boxes;
    }
    

    This works fine and I can retrieve the content, but in order to get to the fields in the Customizer, I have to click on 'Homepage Intro', which then shows me the 'Homepage Intro Text' accordion control, which I have to click in order to see the WYSIWYG field.

    How can I set it up so I get straight to the fields on the first click, ie, on clicking 'Homepage Intro', like the default WordPress controls?

    Also, could I allow users to add content using Blocks (standard WP blocks rather than anything created using MB Blocks) instead of the WYSIWYG in the customizer?

    #48181
    PeterPeter
    Moderator

    Hello,

    You can replace the meta box setting

    'settings_pages' => ['homepage-masthead-text'],

    to

    'panel' => '', to show the top-level section in the customizer

    $meta_boxes[] = [
        'title'          => __( 'Homepage Intro Text', 'wcpp' ),
        'id'             => 'homepage-masthead-wysiwyg',
        'panel' => '',
    ...
    ]

    Please follow the documentation https://docs.metabox.io/extensions/mb-settings-page/#top-level-sections

    Regarding the blocks, if you want to use the Meta Box custom fields with blocks, you need to create/register a custom block to use it. There isn't an option to use the custom fields with standard WordPress blocks.

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.