Created
October 11, 2023 02:28
-
-
Save mt8/6a814f3fb95bf37caabefdcbaaf82924 to your computer and use it in GitHub Desktop.
[WordPress] My Snow MonkeyでAdvanced Posts Blocks のテンプレート上書きをできるようにする
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_filter( | |
'advanced_posts_blocks_default_template_path', | |
function ( $template_path, $name, $query, $args ) { | |
$skin_template_base_dir = __DIR__ . '/override/template-parts/blocks/advanced-posts-blocks/'; | |
if ( array_key_exists( 'p', $query->query ) ) { | |
$skin_template_base_dir .= 'post/'; | |
} else { | |
$skin_template_base_dir .= 'posts/'; | |
} | |
// スタイルの反映 | |
$style_name = ( array_key_exists( 'class_name', $args ) ) ? str_replace( 'is-style-', '', $args['class_name'] ) : ''; | |
if ( ! empty( $style_name ) && file_exists( $skin_template_base_dir . $style_name . '.php' ) ) { | |
$template_path = $skin_template_base_dir . $style_name . '.php'; | |
return $template_path; | |
} | |
if ( file_exists( $skin_template_base_dir . $query->query['post_type'] . '.php' ) ) { | |
$template_path = $skin_template_base_dir . $query->query['post_type'] . '.php'; | |
} | |
return $template_path; | |
}, | |
10, 4 | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment