我有一个博客,它有一个定制的post类型article,链接是http://example.com/article/lorem-ipsum。
如何使用add_rewrite_rule向相同的post http://example.com/article/lorem-ipsum/readers添加新的链接样式,使部件readers向页面http://example.com/article/lorem-ipsum添加GET参数&showReaders=true。
发布于 2019-03-18 11:07:42
您希望使用add_rewrite_endpoint,因为您所关心的是在URL的末尾。
function wpseo331941_reader_endpoint() {
add_rewrite_endpoint('readers', EP_PERMALINK | EP_PAGES);
}
add_action('init', 'wpseo331941_reader_endpoint', 10, 0);//When you want to check if the 'readers' is being used
if ( false !== get_query_var('readers', false) ){
//....
}请注意,false !==必须存在,因为您的查询变量"readers“将有一个空字符串作为其值。
https://wordpress.stackexchange.com/questions/331941
复制相似问题