提问人:RicardoRuizQ 提问时间:8/30/2023 更新时间:9/15/2023 访问量:57
如何在 wordpress 中为模板不加载到 AMP 上做例外?
How to make an exception for a template not to load on AMP in wordpress?
问:
我的网页在AMP上也使用官方插件。我为我的内容使用模板,每次有人发帖时都会使用模板。所有页面都在 AMP 中,但如果我只想只有一个模板不加载到 AMP 中,我该如何实现?我尝试使用函数.php但没有成功
答:
0赞
la_petite_kozel
8/31/2023
#1
您可以通过在模板中使用来实现这一点。amp_is_request
if ( function_exists( 'amp_is_request' ) && amp_is_request() ) {
/* AMP Request */
} else {
/* non AMP Request */
}
否则,您可以在函数中使用过滤器:.php:amp_skip_post
add_action(
'wp',
function() {
$template_slug = get_page_template_slug($post_id);
if ( $template_slug == 'Your template slug' ) {
add_filter( 'amp_skip_post', '__return_true' );
}
}
);
请注意,这两种解决方案都将在非 AMP 模式下加载整页。如果您想在非 AMP 中加载其中一个组件,您可以尝试使用消毒程序,但该页面仍将是 AMP。
评论