Problems with custom routing
-
Hi,
since I am developing on my local machine, I have not generated a UUID, because most of the details are different for the live machine. But I think these are important:
System
- WordPress version 5.9.2
- AMP version 2.2.4
- AMP plugin configured: Yes
- AMP all templates supported: No
- AMP supported templates: is_singular
- AMP supported post types: post, magazin, kaufberatung, roaming, test, testbericht, stoerung, deal
Problem
The AMP Plugin is working fine with most of our custom post types we have set up. We are using our own amp theme in reader mode which also works fine. So no problems until then. But there is one thing we can′t get to work. After spending several days trying to find a solution we have now decided to ask you here.
We are using a custom routing for one of our custom post types (testbericht). Without the routing the url would be /testberichte/post-name. But with our routing it is /handys/xxxxxx/test. The AMP Endpoint we are using is /amp. So that has to be added to the url for viewing the AMP version.
Now if we go to /handys/xxxxxx/test/amp we are instantly redirected to the non-amp version without the endpoint. We have already found out where in the code that happens.
The method redirect_extraneous_paired_endpoint() calls amp_is_available() which calls AMP_Theme_Support::get_template_availability( $wp_query ) which calls $query->is_singular() at the end which returns false. So if we set $query->is_singular = true; and $query->is_single = true; right before the check, the redirect is not happening anymore. But guess what: the amp page still does not work because if is_singular is not set there have to be some general issues with the query because the post is a singular post.As we don′t want to code in the Plugin itself anyway we removed the lines and set up a function for the hook “pre_get_posts” in which we tried out stuff like that:
$query->is_singular = true; $query->is_single = true; $query->is_home = false; $query->set('singular', true); $query->set('is_singular', true); $query->set('post_type', 'testbericht'); $query->set('p', xxxxxx);
but it doesn′t help. At the point the amp plugin is checking for $query->is_singular() the property is not set although we’ve set it before at pre_get_posts as mentioned.
Maybe the plugin resets these properties when specific checks are performed. We do not have a clue anymore. Maybe there is one property we have to set and everything works ?? Maybe the plugin is not able to work with custom routings.
So if someone has an idea how to solve this, we would be very grateful ?? Thank you very much.
- The topic ‘Problems with custom routing’ is closed to new replies.