Written by Manabu Bannai

【wordpress】Genesissのsingle.phpにウィジェットエリアを追加する方法

PROGRAMMING WordPress

WordPressのGenesissというテーマはとても便利ですが、
日本語の情報が少なかったので、備忘録もかねて情報を共有しておきます。

single.phpのコンテンツ上部、コンテンツ下部にウィジェットエリアを追加する方法です。

以下。具体的な方法。

Genesissの子テーマのfunction.phpに以下のコードを追加します。


/** Add the before post section */
genesis_register_sidebar( array(
    'id'        => 'beforepost',
    'name'        => __( 'Before Post  Widget', 'child theme' ),
    'description'    => __( 'This is the Before post section.', 'child theme' ),
) );

/** Add Hook to show widgets before Post Section. */
add_action( 'genesis_before_post_content', 'custom_add_before_post_box', 15 );
function custom_add_before_post_box() {
    if ( is_singular( 'post' ) )
    genesis_widget_area( 'beforepost', array(
        'before' => '<div id="afterpost">',
    ) );
}

/** Add the after post section */
genesis_register_sidebar( array(
    'id'        => 'afterpost',
    'name'        => __( 'After Post  Widget', 'child theme' ),
    'description'    => __( 'This is the after post section.', 'child theme' ),
) );

/** Add Hook to show widgets after Post Section. */
add_action( 'genesis_after_post_content', 'custom_add_after_post_box', 15 );
function custom_add_after_post_box() {
    if ( is_singular( 'post' ) )
    genesis_widget_area( 'afterpost', array(
        'before' => '<div id="beforepost">',
    ) );
}

上記のコードをそのままコピペでokです。
その後、Genesissのヴィジェットエリアを確認すると、セクションが追加されています。

Genesiss

How to Add After Post Widget Area in Genesis 2.0 Framework- WordPress Tips • Crunchify
Genesis Framework 2.0. Tips and Hook References • Crunchify
Genesis Theme Modifications – Customize Genesis Child Themes