admin管理员组文章数量:1130349
I have categories Cats, Dogs and Rabbits.
I would like to change the link used for "dogs" when listing category on the front end to a custom page instead of the category archive.
I have categories Cats, Dogs and Rabbits.
I would like to change the link used for "dogs" when listing category on the front end to a custom page instead of the category archive.
Share Improve this question asked Oct 27, 2018 at 9:41 David BarclayDavid Barclay 58 bronze badges3 Answers
Reset to default 1Your goal seems to be to change the link which is output when listing the categories rather than making the existing link point to a different page as my last answer assumed. So I am going to try a different answer with a different solution.
Using the filter term_link in the function get_term_link() you can change the link which is generated for a specific category.
function wpse_317747_filter_term_link( $termlink, $term, $taxonomy ) {
if ( "category" !== $taxonomy || "dogs" !== $term->slug ) {
return $termlink;
}
return get_permalink( $target_page_id );
}
add_filter( "term_link", "wpse_317747_filter_term_link", 10, 3 );
This changes the generated link if working on category taxonomy and the current term slug is dogs. Just set $target_page_id to correspond to the page you want the link to point to.
For special behavior for a category, you can add a template file for the specific category. Such files are called Taxonomy Templates. Creating the file ´category-dogs.php´ in your theme's directory will make wordpress load this file when the category with the slug ´dogs´ is requestd. As model for the new file you can copy the original ´category.php´ in your theme or just redirect the user to another existing page.
Depending on how you display categories, you could create a menu where the link to Dogs is a page, instead of the category. Do you have posts in the Dogs category?
I have categories Cats, Dogs and Rabbits.
I would like to change the link used for "dogs" when listing category on the front end to a custom page instead of the category archive.
I have categories Cats, Dogs and Rabbits.
I would like to change the link used for "dogs" when listing category on the front end to a custom page instead of the category archive.
Share Improve this question asked Oct 27, 2018 at 9:41 David BarclayDavid Barclay 58 bronze badges3 Answers
Reset to default 1Your goal seems to be to change the link which is output when listing the categories rather than making the existing link point to a different page as my last answer assumed. So I am going to try a different answer with a different solution.
Using the filter term_link in the function get_term_link() you can change the link which is generated for a specific category.
function wpse_317747_filter_term_link( $termlink, $term, $taxonomy ) {
if ( "category" !== $taxonomy || "dogs" !== $term->slug ) {
return $termlink;
}
return get_permalink( $target_page_id );
}
add_filter( "term_link", "wpse_317747_filter_term_link", 10, 3 );
This changes the generated link if working on category taxonomy and the current term slug is dogs. Just set $target_page_id to correspond to the page you want the link to point to.
For special behavior for a category, you can add a template file for the specific category. Such files are called Taxonomy Templates. Creating the file ´category-dogs.php´ in your theme's directory will make wordpress load this file when the category with the slug ´dogs´ is requestd. As model for the new file you can copy the original ´category.php´ in your theme or just redirect the user to another existing page.
Depending on how you display categories, you could create a menu where the link to Dogs is a page, instead of the category. Do you have posts in the Dogs category?
本文标签: categoriesHow do I rewrite a single category link to point to a custom page
版权声明:本文标题:categories - How do I rewrite a single category link to point to a custom page? 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749204910a2332397.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论