php – add partial menu and widget in customizer

Question

I added a minimalistic php code to the function.php. this is a menu and a widget. both should be changeable as quickly as possible. the logo has a pencil icon. this allows you to quickly access the settings to change the logo. In the other way example, I found out how I could do it if necessary. However, I would prefer to be able to use the widget area so that I can insert different building blocks. Unfortunately I can’t get any further because I don’t have a pen in the first example (unfortunately also in the menu) and the second example isn’t as flexible as the first. I hope that someone can help me. I don’t want to just take php code from an existing theme. they are very complex and I am currently learning.

pen symbol the customizer pencil

    <?php
    // add menu
    function register_my_menus() {
      register_nav_menus( array(
        'top_menu' => __( 'Top Menu', 'theme' ),
        //'footer_menu' => __( 'Footer Menu', 'theme' ),
        'panel' =>'',
      ) );
    }
    add_theme_support( 'init', 'register_my_menus' );
    <?php
    // add widget
    function theme_register_widgets() {

      // Widget Main-1 H1
      register_sidebar( array(
        'name' => __( 'main-1-h1 ', 'theme' ),
        'id' => 'main-1-h1',
        'description' => __( 'main-1-h1', 'theme' ),
        'before_widget' => '<aside id="%1$s" class="widget %2$s clearfix">',
        'after_widget' => '</aside>',
      ) );

    }
    add_action( 'widgets_init', 'theme_register_widgets', 20 );

    ?>
    //Another way
<?php
/* Customizer fields */
 
function your_customizer_settings($wp_customize) {
    $wp_customize->add_section('footer_section', array(
        'title' => __('Footer Section', 'healthtech'),
        'panel' =>'',
    ));
    /*
     * Settings for copyright text
     */
    $wp_customize->add_section('footer_section', array(
        'title' =>__('Footer Section', 'healthtech'),
        'panel' =>'',
    ));
    /*
     * Settings for copyright text
     */
    $wp_customize->add_setting('copyright_text', array(
        'default' => '2342',
        'transport' => 'postMessage'
    ));
    $wp_customize->add_control(new WP_Customize_Control($wp_customize, 'copyright_text', array(
        'label' => __('Copyright Text', 'healthtech'),
        'section' => 'footer_section',
        'settings' => 'copyright_text',
            )
            )
    );
    $wp_customize->selective_refresh->add_partial('copyright_text', array(
        'selector' => 'span#copy-write', // You can also select a css class
        'render_callback' => 'check_copy_right_text',
    ));
}
// Customizer action
add_action('customize_register', 'your_customizer_settings');
 
function check_copy_right_text(){
   echo get_theme_mod('copyright_text');
 }
?>

0
knefie 2 weeks 2021-07-13T11:53:05-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse