Search code examples
wordpresswordpress-themingcustom-wordpress-pageswordpress-rest-api

How to add wordpress customize section in custom post


How can I create that option please see this image on my custom theme? I can make the theme using a custom post but I want to make website similar to this image. Thank you.


Solution

  • The items shown in the image are 'Customizer Sections' and are added via the customizer API. You would use some code like this to add a section. Note: You would also need to add settings and controls.

    <?php
    function mytheme_customize_register( $wp_customize ) {
        //All our sections, settings, and controls will be added here
        $wp_customize->add_section( 'mytheme_new_section_slider' , array(
            'title'      => __( 'Slider Settings', 'mytheme' ),
            'priority'   => 30,
        ) );
        // you would also have settings and controls that are added to the section.
        // if you add a section and it contains no controls it will not appear.
    }
    add_action( 'customize_register', 'mytheme_customize_register' );
    

    Here's some documentation about the add_section method: https://codex.wordpress.org/Class_Reference/WP_Customize_Manager/add_section

    And some about the overall process, including adding settings and controls: https://codex.wordpress.org/Theme_Customization_API