• Resolved Omeprazol

    (@omeprazol)


    I’ve installed on a website that heavily uses custom post types and it appears that doesn’t work. Is this correct (or am I doing something wrong) and if they are not supported, are there plans to support them soon?

    E.g. we have a custom post type news and one for reviews, both would be great for AMP.

    https://www.ads-software.com/plugins/amp/

Viewing 9 replies - 1 through 9 (of 9 total)
  • 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 );
    }
    Thread Starter Omeprazol

    (@omeprazol)

    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?

    Thread Starter Omeprazol

    (@omeprazol)

    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]&amp=1', 'top');
    Thread Starter Omeprazol

    (@omeprazol)

    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.

    fysalyaqoob

    (@fysalyaqoob)

    I have a cpt services. And I am using slug as post name follows this guide: https://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!

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Does AMP for WordPress support custom post types?’ is closed to new replies.