更新 2021 / 2 / 20

「外観>カスタマイズ」にオリジナル項目を追加する

WordPressの管理画面にある「外観」をクリックすると、その中に「カスタマイズ」という項目があります。

参考:https://delaymania.com/202002/wordpress/wp-customizer-setting/

functions.php


                function theme_customizer_tw($wp_customize) {
                  $wp_customize->add_section( 'sns_acount', array(
                    'title'     => 'SNSアカウント',
                    'priority'  => 201,
                  ));
                    $wp_customize->add_setting( 'sns_tw', array(
                      'default'   => '',
                      'type'      => 'option',
                      'transport' => 'postMessage',
                    ));
                      $wp_customize->add_control( 'sns_acount_tw', array(
                        'settings'  => 'sns_tw',
                        'label'     => 'Twitterアカウント',
                        'description' => '<small>Twitterアカウントを入力してください</small>',
                        'section'   => 'sns_acount',
                        'type'      => 'text',
                      ));
                }
                add_action('customize_register', 'theme_customizer_tw');
                

テンプレートの出力したい箇所


                    <?php echo get_option( 'add_settingに設定した文字列(上記で言うとsns_tw)' ); ?>