[amp_sidebar]
AMPプラグインで、カスタム投稿タイプの、AMP表示を行うには、以下のフィルターをfunctions.phpに追加する必要がありそうです。
以下のコードは、productというカスタム投稿タイプで、AMPを有効にします。
functions.php
if ( has_action( 'amp_init' ) ) {
add_action( 'amp_init', 'raindrops_amp_add_cpt' );
function raindrops_amp_add_cpt() {
if ( defined( 'AMP_QUERY_VAR' ) ) {
add_post_type_support( 'product', AMP_QUERY_VAR );
}
}
}
カスタム投稿用のカスタムテンプレート
AMPプラグインの、amp/templates/single.phpをコピーして、テーマに、raindrops-amp-product-template.phpを作成し、フィルターをfunctions.phpに追加します。
productを必要な投稿タイプに書き換えます。
functions.php
if ( has_filter( 'amp_post_template_file' ) ) {
add_filter( 'amp_post_template_file', 'raindrops_amp_set_product_template', 10, 3 );
function raindrops_amp_set_product_template( $file, $type, $post ) {
$custom_template= get_template_directory() . '/raindrops-amp-product-template.php';
if ( 'single'=== $type && 'product'=== $post->post_type && file_exists( $custom_template ) ) {
return $custom_template;
}
return $file;
}
}
表示を確認したら、テンプレートをカスタマイズします。
(カスタマイザープリビューのテンプレートは、現在のところ変更されないみたいです。)