Skip to content

Instantly share code, notes, and snippets.

@webbingstudio
Last active January 4, 2023 08:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save webbingstudio/f2c402f3f1173c3eccd02c8bde41c186 to your computer and use it in GitHub Desktop.
Save webbingstudio/f2c402f3f1173c3eccd02c8bde41c186 to your computer and use it in GitHub Desktop.
WordPressテーマ「Snow Monkey」のフックを利用して、カスタム投稿タイプ「test」のアーカイブの、1ページ目の先頭にウィジェットを追加する
function mysm_widgets_init() {
register_sidebar( array(
'name' => 'テスト: 本文上',
'id' => 'mysm-widget-test-main-top',
'before_widget' => '<div id="%1$s" class="c-widget widget_block">',
'after_widget' => '</div>',
) );
}
add_action( 'widgets_init', 'mysm_widgets_init', 10 );
function mysm_add_test_widget() {
if ( ( is_post_type_archive( 'test' ) ) && ( !is_paged() ) && ( is_active_sidebar( 'mysm-widget-test-main-top' ) ) ) {
echo '<div class="l-archive-top-widget-area" data-is-slim-widget-area="false" data-is-content-widget-area="false">';
dynamic_sidebar( 'mysm-widget-test-main-top' );
echo '</div>';
}
}
add_action( 'snow_monkey_prepend_main', 'mysm_add_test_widget', 10 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment