自定义 Post 类型的 WordPress AMP 和自己的 URL
WordPress AMP for Custom Post Types with own URL
我想在 WordPress 中使用带有自定义 Post 类型的 AMP。
出于这个原因,我将以下代码添加到我的 functions.php:
add_action( 'amp_init', 'xyz_amp_add_review_cpt' );
function xyz_amp_add_review_cpt() {
add_post_type_support( 'xyz-review', AMP_QUERY_VAR );
}
代码来自插件官方文档:https://github.com/Automattic/amp-wp/blob/master/readme.md#custom-post-type-support
在那之后,我按照他们所说的刷新了我的重写规则。
不幸的是,它对我的 CPT 不起作用。仅适用于普通帖子。
我认为这是因为我的 CPT 没有 slug。 URL 与帖子相同:示例。com/custom-post-type-post/
如果我在 CPT 上添加一个 slug,AMP 就会工作。
但是我做不到。
是否有任何其他解决方案可以解决此问题?
试试这个
add_rewrite_rule( '^([^/]+)+[\/]+(amp)/?$', 'index.php?post_type=xyz-review&name=$matches[1]&=1', 'top' );
我想在 WordPress 中使用带有自定义 Post 类型的 AMP。 出于这个原因,我将以下代码添加到我的 functions.php:
add_action( 'amp_init', 'xyz_amp_add_review_cpt' );
function xyz_amp_add_review_cpt() {
add_post_type_support( 'xyz-review', AMP_QUERY_VAR );
}
代码来自插件官方文档:https://github.com/Automattic/amp-wp/blob/master/readme.md#custom-post-type-support
在那之后,我按照他们所说的刷新了我的重写规则。 不幸的是,它对我的 CPT 不起作用。仅适用于普通帖子。
我认为这是因为我的 CPT 没有 slug。 URL 与帖子相同:示例。com/custom-post-type-post/
如果我在 CPT 上添加一个 slug,AMP 就会工作。 但是我做不到。
是否有任何其他解决方案可以解决此问题?
试试这个
add_rewrite_rule( '^([^/]+)+[\/]+(amp)/?$', 'index.php?post_type=xyz-review&name=$matches[1]&=1', 'top' );