HI there,
We are using the newspaper theme (Version: 10.4) with tagdiv mobile, composer, standard pack and official AMP plugins.
We are using mobile + AMP theme in Transitional mode
We would like to customize the template for posts, currently the AMP pages uses the template /wp-content/plugins/td-composer/mobile/single.php
Based on documentation of AMP plugin I added the newspaper-child theme and created a folder called amp in the child theme root and copied the single.php file to this folder renamed it to blog.php and created another copy and renamed to home.php, then added the following filter in the child theme functions.php:
add_filter( 'amp_post_template_file', function ( $template, $template_type, $post ) {
if ( 'page' === $template_type && 'page' === get_option( 'show_on_front' ) ) {
if ( (int) get_option( 'page_on_front' ) === $post->ID ) {
$template = dirname( __FILE__ ) . '/amp/home.php';
} elseif ( (int) get_option( 'page_for_posts' ) === $post->ID ) {
$template = dirname( __FILE__ ) . '/amp/blog.php';
}
}
return $template;
}, 10, 3 );
However the amp pages still called the posts template single.php from the td-composer plugin!!
I also tried adding the following filter in child theme functions.php:
add_filter( 'amp_post_template_file', function ( $file, $type ) {
if ( 'single' === $type ) {
$file = dirname( __FILE__ ) . '/amp/blog.php';
}
return $file;
}, 10, 3 );
This also doesn’t work.
Please let me know how do I create a custom template for posts only AMP pages without modifying the single.php in the td-composer plugin because when the plugin is updated, my customization will be lost.
Thanks!
Hello!
Please note that customization is not covered by the support team: https://forum.tagdiv.com/newspaper-theme-support/
For customization and other services you can contact our custom work team here and they can help/suggest you a great solution: https://tagdiv.com/premium-customization-services/
Thank you!
Thanks Bettina for the suggestion. But I guess you didn’t read thoroughly I am not looking at you guys to customize a template; I’ll take care of the customization.
All I need is for the support team to point me to the function /hook that is responsible for the AMP pages to pick the single.php from the td-composer plugin and not from the child theme.
Hello!
AMP use the functions from Mobile Theme: wp-content/plugins/td-composer/mobile/amp/functions.php, also check here: \wp-content\plugins\td-composer\mobile\functions.php
But, please note that any change you make in the files after update will be overwritten and you have to make the changes again. Better save the code somewhere and then apply it again after update.
Hope that helps you somehow!
Thank you!