Something like this should work:
add_action( 'init', 'xyz_amp_add_cpt', 9 ); // before amp_init
function xyz_amp_add_cpt() {
if ( ! defined( 'AMP_QUERY_VAR' ) ) {
return; // amp probably not installed...
}
add_post_type_support( 'reviews', AMP_QUERY_VAR );
}
Thank you so much for the quick reply, that worked! The last thing is, the automatically generated URL in the header is my pretty URL /amp/ however only ?amp=1 works, anyway to fix that? Either by letting the plugin generate the ?amp=1 links or by properly parsing the URL?
I already flushed the permalinks BTW.
What dos your permalink structure look like? Do you have any plugins that modify or change it or rewrites in any way?
I have to admit this is kind of difficult for me, due to the regexes, but this is how I once defined the URLs for the custom post types 😉 he reviews use a multipage plugin, which also makes them a bit more complicated.
add_rewrite_rule(‘review/[^/]+-([0-9]{1,})/[^/]+-([0-9]+)?/?$’, ‘index.php?post_type=review&p=$matches[1]&pageid=$matches[2]’, ‘top’);
add_rewrite_rule(‘article/[^/]+-([0-9]{1,})/[^/]+-([0-9]+)?/?$’, ‘index.php?post_type=review&p=$matches[1]&pageid=$matches[2]’, ‘top’);
add_rewrite_rule(‘(news|article|review)/([A-z-0-9]+)-([0-9]+)’, ‘index.php?post_type=$matches[1]&p=$matches[3]’, ‘top’);
add_rewrite_rule(‘(news|article|review)/([0-9]+)’, ‘index.php?post_type=$matches[1]&p=$matches[2]’, ‘top’);
I hope you can help, thanks in advance!
You can probably add the AMP rules manually as well:
add_rewrite_rule('(news|article|review)/([0-9]+)/amp/?', 'index.php?post_type=$matches[1]&p=$matches[2]&=1', 'top');
Thank you, that works! Thanks a lot!
I too am trying to get Amp to work with a custom post type. What would be the same above AMP rule written in apache please?
Even if you are using apache, you could still use this rewrite rule in your functions.php file and have it work.
Otherwise, you’re going to have to make sure to cover your whole URL structure in the rewrite rule.
I have a cpt services. And I am using slug as post name follows this guide: http://wordpress.stackexchange.com/questions/203951/remove-slug-from-custom-post-type-post-urls
amp is not working without cpt slug. How I can fix this.
Please help me in this regard.
Thank you!