8

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.

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!

The reason I'm coding manually is to

  1. add proper structured data
  2. amp-analytics code and
  3. make sure everything will be indexed properly.
clemens
  • 16,716
  • 11
  • 50
  • 65
  • 1
    Can you give more information about what you mean by no luck? Any errors? What exactly have you attempted? Can you add code to your question that might be relevant? – Fencer04 Sep 29 '16 at 13:34
  • Agree fully with the comments on plugin conflicts, and problems with bloated code that defeat the purpose of creating AMP pages. We created a solid HTML AMP template that validates, and manually built out a full AMP page versions. It was well worth the effort. We advise our clients to avoid WP plugin solutions. Personally, like so much of WP, it's for people who do not have the skill to do the work without a plug-n-play option. – Jim Hobson Dec 16 '17 at 02:42

2 Answers2

8

Have you tried this?

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;
}

Source link.

Vaidas
  • 1,494
  • 14
  • 21
moorewebx
  • 125
  • 1
  • 7
  • For anyone stumbling upon this answer in the future, you need to put this code in your theme's functions.php file according to [this](https://wordpress.org/support/topic/implementing-amp-without-amp-plugin/#post-9078233). – cabrerahector Apr 08 '21 at 18:13
0

We just created a AMP Template page outside of the WordPress environment. Programmed it with PHP/HTML. This makes the Fastest, Google Verified AMP page. Then just link to it from inside WordPress.

Note: We created sub-directories outside of WP to hold the AMP pages for better design control. Just watch out for the "Slug vs. sub-directory" name conflicts that will arise.

We also looked at all the AMP plugin, they are garbage as of 4/1/2017. They have to high of a code overhead to be SEO competitive. That overhead makes the page slower and a now WP AMP concept.