@amineharoun Can you share the full function you are using to create the custom post type? The following works fine for me when testing.
'rewrite' => array('slug' => '/', 'with_front' => false),
Notice the apostrophe, as opposed to the quotation marks in the code snippet you provided.
Ensure you also refresh permalinks, via “settings > permalinks” tab. But please share the full code and we can take a look.
Thread Starter
wpdev
(@amineharoun)
Hi, thanks for your reply
So, when you try to go to custom post AMP version : https://actufeed.com/leffet-domino-du-transfert-de-neymar-sur-le-mercato-italien/amp (you will be redirect to ‘not-amp version’)
here is the code to generate the custom post :
$args = array(
'labels' => $labels,
'description' => __('Description.', 'your-plugin-textdomain'),
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'show_in_menu' => true,
'query_var' => true,
'rewrite' => array('slug' => '/', 'with_front' => false),
'capability_type' => 'post',
'has_archive' => true,
'hierarchical' => false,
'menu_position' => null,
'supports' => array('title', 'author', 'thumbnail', 'editor'),
'taxonomies' => array('category')
);
register_post_type('youtube', $args);
Maybe the amp plugin cant find the post to show without custom posty type slug ?
Looking at the URL structure when hovering over any of the YouTube videos on your homepage they all result in 404 errors, manually inserting the ‘youtube/’ into the URL is fine.
Do you have any CPT, redirect or permalinks plugin active on your site?
Thread Starter
wpdev
(@amineharoun)
I’m sorry, it was a bug, I added that code to solve it :
function na_remove_slug($post_link, $post, $leavename)
{
if ('youtube' != $post->post_type || 'twitter' != $post->post_type || 'facebook' != $post->post_type || 'publish' != $post->post_status) {
return $post_link;
}
$post_link = str_replace('/' . $post->post_type . '/', '/', $post_link);
return $post_link;
}
add_filter('post_type_link', 'na_remove_slug', 10, 3);
function na_parse_request($query)
{
if (!$query->is_main_query() || 2 != count($query->query) || !isset($query->query['page'])) {
return;
}
if (!empty($query->query['name'])) {
$query->set('post_type', array('post', 'youtube', 'twitter', 'facebook', 'page'));
}
}
add_action('pre_get_posts', 'na_parse_request');
So, as you see, normal page works fine, but AMP dosnt work (it redirect to not amp version) : https://actufeed.com/leffet-domino-du-transfert-de-neymar-sur-le-mercato-italien/amp
I am unable to replicate the same problem from my side. Can you create another CTP using a plugin such as this and see if the same issue arises? There could be other functions you have active, or plugins causing the problem.
Thread Starter
wpdev
(@amineharoun)
Can I give you access so you see directly what I have installed ?
@amineharoun We can take a look if you want to setup a staging site. Before that you can check disabling all other plugins on that staging site, and maybe even testing another theme.
If you don’t have a staging site setup you can create a copy of your website using a plugin such as Duplicator.
Thread Starter
wpdev
(@amineharoun)
Thank you, can you give me your email to give you access ?
Before accessing your site can you check the following with the backup/staging site:
– Check does the issue exist with a different theme (Add the same CPT function)
– Check does the issue exist with other plugins deactivated.
Please share your Site Health info also.
@amineharoun I can see the AMP versions of your CPT’s are working now. Were you able to figure out the problem?