Closed webliskatech closed 7 years ago
The link https://www.tuluzz.com/hardwares/ corresponds to a kind of index page where multiple posts are shown. Could you provide links to actual posts of the custom types?
The check indicated is behaving appropriately since the link is not a post. Closing this for now; please reopen if still an issue and provide more information to try to track it down.
@amedina Hey I'm having the same issue. I have a testimonials custom post type, and have the archive option enabled. When I add this code snippet I expect both single testimonial pages and the testimonials archive to be redirected the the ?amp url when I append /amp.
The single post type page works /testimonials/chris/amp
The archive page does not and throws a 404 error /testimonials/amp
add_action('amp_init', function () {
add_post_type_support('testimonials', amp_get_slug());
});
@myleshyson The classic mode of the plugin only supports AMP on singular post type templates. If you want AMP on non-singular templates, you'll need to switch to the new Paired or Native modes. In these modes, you're active theme's templates and stylesheets will be served in the AMP responses and all URLs of your site are then able to be served as AMP.
@westonruter Hey thanks for getting back. I actually am using the paired option and it definitely keeps giving me a 404 error.
This is the workaround I came up with to get it to work but ideally this would work out of the box. I had to write some custom code to get the front page to work as well.
add_action('parse_query', function ($query) {
$slug = amp_get_slug();
$name = $query->query['name'] ?? null;
if ($name = $slug && $_SERVER['REQUEST_URI'] === "/$slug") {
$query->is_home = false;
$query->is_page = true;
$query->is_singular = true;
$query->set('page_id', get_option('page_on_front'));
}
});
add_filter('request', function ($query_vars) {
$slug = amp_get_slug();
$name = $query->query['name'] ?? null;
$postType = $query_vars['post_type'] ?? false;
if ($name = $slug && $_SERVER['REQUEST_URI'] === "/$slug") {
$query_vars[amp_get_slug()] = 1;
}
if (isset($query_vars['name']) && $query_vars['name'] === amp_get_slug() && $postType === 'testimonials') {
$query_vars[amp_get_slug()] = 1;
}
if (isset($query_vars[amp_get_slug()]) && '' === $query_vars[amp_get_slug()]) {
$query_vars[amp_get_slug()] = 1;
}
return $query_vars;
});
@myleshyson You shouldn't need this. Without your custom code, look at the non-AMP version of the page. In the page source, you should see an amphtml
link in the head. You should see that it ends in ?amp
not /amp/
. The /amp/
URLs are only used in classic mode.
@westonruter ah ok thanks! That makes sense now. I guess it is still necessary for us then because we like the /amp/ url better than using the ?amp url.
Why does the URL matter? Normally the full paired URL is not exposed when accessing an AMP page via Google Search, Twitter, etc.
I guess it doesn't haha. Purely an OCD vanity thing.
Hello
I tried to follow the exact guide to add support for custom post types for AMP.
Here is my blog: https://www.tuluzz.com
The Setup I am Using:
So, According to the Solution, I added this code to my Site:
Also, Flushed my Permalinks Structure again as per the documentation.
So, When I checked the https://www.tuluzz.com/hardwares/amp
it should work, but its not working but giving a 404 Error Page.
Please help, what I can do about this to solve it.