admin管理员组文章数量:1390914
I use WordPress.
I need to show page instead of category when they have same slug.
I have category called "Acne" with the slug "Acne"
page and the category have the same slug.
When I write www.example/acne
, the category page is opening,
I need to make WordPress to show the page instead of category when they have the same slug.
Is there any way to do that.
I use WordPress.
I need to show page instead of category when they have same slug.
I have category called "Acne" with the slug "Acne"
page and the category have the same slug.
When I write www.example/acne
, the category page is opening,
I need to make WordPress to show the page instead of category when they have the same slug.
Is there any way to do that.
Share Improve this question edited Jun 15, 2020 at 8:21 CommunityBot 1 asked Feb 4, 2015 at 5:17 JaiJai 113 bronze badges 2- Asking for plugin recommendation is off-topic. edit and rewrite your question for actual cause. – Mayeenul Islam Commented Feb 4, 2015 at 5:19
- I Am Trying To Make A Silo Structure Site With Wordpress. – Jai Commented Feb 4, 2015 at 5:36
1 Answer
Reset to default 2You can hook onto parse_request
and trick WordPress into thinking it matched a page permalink if one exists with the same slug for a category term:
/**
* Override query for pages that match a category slug.
*
* @param WP $wp
*/
function wpse_177014_category_to_page ( $wp ) {
if ( ! empty( $wp->query_vars['category_name'] ) && get_page_by_path( $slug = $wp->query_vars['category_name'] ) ) {
if ( ! empty( $wp->query_vars['paged'] ) )
$page = $wp->query_vars['paged'];
else
$page = '';
$wp->matched_query = "pagename=$slug&page=$page";
$wp->query_vars = array(
'pagename' => $slug,
'page' => $page,
);
}
}
add_action( 'parse_request', 'wpse_177014_category_to_page' );
本文标签: urlsHow to make pages slug have priority over any category
版权声明:本文标题:urls - How to make pages slug have priority over any category 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744585731a2614185.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论