• Resolved Marcusvot

    (@marcusvot)


    i have this rewrite for my custom post “example”:
    add_rewrite_tag( ‘%sub%’, ‘([^/]*)’ );
    add_rewrite_rule(
    ‘^’.$example[‘post_type’].’/([^/]*)/([^/]*)/?$’,
    ‘index.php?’.$example[‘post_type’].’=$matches[1]&sub=$matches[2]’,
    ‘top’
    );
    A exemple of this rewrite:
    site.com/exemple/post-slug/download/
    site.com/exemple/post-slug/old-version-2/

    If i use site.com/exemple/post-slug/amp/ this dont work, and dont show amp page.

    there is the possibility to call an amp page with the query var %sub% ?

    or is there another way to make this work?

    I hope you understand me, because I don’t speak English.

Viewing 7 replies - 1 through 7 (of 7 total)
  • @marcusvot Can you share your site URL or the href value you see in the <link rel="amphtml"... tag on any of your non AMP posts?

    Plugin Author Weston Ruter

    (@westonruter)

    @marcusvot How are you handling generation of the permalink? In other words, for your custom post type are you forcing get_permalink() to return something different than what WordPress normally does? Please share that code.

    I think what is needed is to avoid using the /amp/ endpoint altogether. This code can do that:

    // Force using query var instead of endpoint.
    add_filter( 'amp_pre_get_permalink', function( $pre, $post_id ) {
    	return add_query_arg( amp_get_slug(), '1', get_permalink( $post_id ) );
    }, 10, 2 );
    Thread Starter Marcusvot

    (@marcusvot)

    after researching a lot about rewriting rules I found this solution: In my single.php I added this code that I found in the plugin:

    if (get_query_var (‘sub’) == ‘amp’) {amp_render (); }

    This loads the amp template perfectly!

    Can this create a problem?

    Plugin Author Weston Ruter

    (@westonruter)

    I do not recommend doing that.

    Does it not work if you add ?amp=1 to the URL?

    Thread Starter Marcusvot

    (@marcusvot)

    yes, it works that way too. However for reasons of my mind, who likes everything organized I would like to use friendly url, even for something not apparent. Please do not block this option in future updates. ??

    Plugin Author Weston Ruter

    (@westonruter)

    There is no difference in the URL for /amp/ vs ?amp=1. The latter is the only version that will be directly supported in the future. Other URL schemes will be allowed, but they will be up to you to support. See https://github.com/ampproject/amp-wp/issues/2204

    Thread Starter Marcusvot

    (@marcusvot)

    I will see the URL you sent me. Thank you very much for your attention and help.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘AMP in custom post whit extra url parameters’ is closed to new replies.