Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding AMP pages to Wordpress manually without a plugin

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.
like image 261
Scott Schneider Avatar asked Sep 29 '16 13:09

Scott Schneider


1 Answers

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.

like image 71
moorewebx Avatar answered Oct 19 '22 03:10

moorewebx