无需插件即可手动将 AMP 页面添加到 Wordpress [英] Adding AMP pages to Wordpress manually without a plugin

查看:25
本文介绍了无需插件即可手动将 AMP 页面添加到 Wordpress的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要手动编码我的 AMP 页面,并将它们添加到我的 Wordpress 网站,这样我才能确保它们完美无缺.我使用的所有插件都没有完成我需要的一切,并导致 Search Console 出现错误.

I need to code my AMP Pages manually, and add them to my Wordpress site so I can make sure they are perfect. All the plugins I've used have not done everything I need, and cause errors in Search Console.

我已经创建了一个可以玩的子主题,并且一直在尝试添加一个新的 PHP 页面模板,但没有成功!

I've already created a child theme to play around in, and have been attempting to add a new PHP page template, but no luck!

我手动编码的原因是

  1. 添加适当的结构化数据
  2. amp-analytics 代码和
  3. 确保所有内容都正确编入索引.

推荐答案

你试过这个吗?

define( 'AMP_QUERY_VAR', apply_filters( 'amp_query_var', 'amp' ) );

add_rewrite_endpoint( AMP_QUERY_VAR, EP_PERMALINK );

add_filter( 'template_include', 'amp_page_template', 99 );

function amp_page_template( $template ) {

    if( get_query_var( AMP_QUERY_VAR, false ) !== false ) {


        if ( is_single() ) {

            $template = get_template_directory() .  '/amp-single.php';

        } 

    }

    return $template;
}

来源link.

这篇关于无需插件即可手动将 AMP 页面添加到 Wordpress的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆