web-dev-qa-db-ja.com

サイドバーウィジェットの名前を変更する

動的サイドバーを作成しました。それらは正常に機能しており、ウィジェット領域に表示されます。

ただし、各サイドバーに表示される名前をカスタマイズしたいです。

そのため、現在、各サイドバーの名前は「サイドバー1」、「サイドバー2」などです。

代わりに、 "About Sidebar"、 "Toolkit Sidebar"のようなものを言ってほしいのです。

これはタイトルではありません(そのフィールドは空白で、ユーザーは好きなテキストを入力できます)。

助けてくれてありがとう!ジェフ

その方法がわからない。

5
Jeff Tancil

Register_sidebar呼び出しで 'Name'パラメーターを使用してください。たとえば、デフォルトのTwenty Tenテーマの次のコード、351行を参照してください。

function twentyten_widgets_init() {
    // Area 1, located at the top of the sidebar.
    register_sidebar( array(
        'name' => __( 'Primary Widget Area', 'twentyten' ),
        'id' => 'primary-widget-area',
        'description' => __( 'The primary widget area', 'twentyten' ),
        'before_widget' => '<li id="%1$s" class="widget-container %2$s">',
        'after_widget' => '</li>',
        'before_title' => '<h3 class="widget-title">',
        'after_title' => '</h3>',
    ) );

    // Area 2, located below the Primary Widget Area in the sidebar. Empty by default.
    register_sidebar( array(
        'name' => __( 'Secondary Widget Area', 'twentyten' ),
        'id' => 'secondary-widget-area',
        'description' => __( 'The secondary widget area', 'twentyten' ),
        'before_widget' => '<li id="%1$s" class="widget-container %2$s">',
        'after_widget' => '</li>',
        'before_title' => '<h3 class="widget-title">',
        'after_title' => '</h3>',
    ) );

    // Area 3, located in the footer. Empty by default.
    register_sidebar( array(
        'name' => __( 'First Footer Widget Area', 'twentyten' ),
        'id' => 'first-footer-widget-area',
        'description' => __( 'The first footer widget area', 'twentyten' ),
        'before_widget' => '<li id="%1$s" class="widget-container %2$s">',
        'after_widget' => '</li>',
        'before_title' => '<h3 class="widget-title">',
        'after_title' => '</h3>',
    ) );

    // Area 4, located in the footer. Empty by default.
    register_sidebar( array(
        'name' => __( 'Second Footer Widget Area', 'twentyten' ),
        'id' => 'second-footer-widget-area',
        'description' => __( 'The second footer widget area', 'twentyten' ),
        'before_widget' => '<li id="%1$s" class="widget-container %2$s">',
        'after_widget' => '</li>',
        'before_title' => '<h3 class="widget-title">',
        'after_title' => '</h3>',
    ) );

    // Area 5, located in the footer. Empty by default.
    register_sidebar( array(
        'name' => __( 'Third Footer Widget Area', 'twentyten' ),
        'id' => 'third-footer-widget-area',
        'description' => __( 'The third footer widget area', 'twentyten' ),
        'before_widget' => '<li id="%1$s" class="widget-container %2$s">',
        'after_widget' => '</li>',
        'before_title' => '<h3 class="widget-title">',
        'after_title' => '</h3>',
    ) );

    // Area 6, located in the footer. Empty by default.
    register_sidebar( array(
        'name' => __( 'Fourth Footer Widget Area', 'twentyten' ),
        'id' => 'fourth-footer-widget-area',
        'description' => __( 'The fourth footer widget area', 'twentyten' ),
        'before_widget' => '<li id="%1$s" class="widget-container %2$s">',
        'after_widget' => '</li>',
        'before_title' => '<h3 class="widget-title">',
        'after_title' => '</h3>',
    ) );
}
/** Register sidebars by running twentyten_widgets_init() on the widgets_init hook. */
add_action( 'widgets_init', 'twentyten_widgets_init' );
5
sorich87