admin管理员组文章数量:1322850
Instead of the project archives in my Divi theme being at /project_category/[category name]/
I want them to go to /portfolios/#[category name]
.
I modified the following code from this question and added it to my child theme's functions.php file.
function my_category_redirect()
{
if ( is_category( ) ) {
$category = get_queried_object();
$cat_id = $category->term_id;
$url = site_url( '/portfolios/#' . $cat_id);
wp_safe_redirect( $url, 301 );
exit();
}
}
add_action( 'template_redirect', 'my_category_redirect' );
However this is not working. The project categories are still going to /project_category/[category name]/
. I can't tell if the my_category_redirect function is even being called.
Any help is much appreciated!
Instead of the project archives in my Divi theme being at /project_category/[category name]/
I want them to go to /portfolios/#[category name]
.
I modified the following code from this question and added it to my child theme's functions.php file.
function my_category_redirect()
{
if ( is_category( ) ) {
$category = get_queried_object();
$cat_id = $category->term_id;
$url = site_url( '/portfolios/#' . $cat_id);
wp_safe_redirect( $url, 301 );
exit();
}
}
add_action( 'template_redirect', 'my_category_redirect' );
However this is not working. The project categories are still going to /project_category/[category name]/
. I can't tell if the my_category_redirect function is even being called.
Any help is much appreciated!
Share Improve this question edited Sep 18, 2020 at 4:24 clayRay asked Sep 17, 2020 at 8:01 clayRayclayRay 1351 silver badge10 bronze badges1 Answer
Reset to default 1Your action callback probably gets called, but it could be that the if-statement that just fails. Are you using the default "category" taxonomy (i.e. Dashboard > Posts > Categories) or a custom taxonomy (i.e. Dashboard > {my-post-type} > {my-taxonomy}) as the project category?
If you're using a custom taxonomy, then you should use is_tax('my-taxonomy') instead of is_category() as the latter checks for the default category, not custom ones.
But, you can temporarily add a die('it works');
to your callback also, before the if statement, to verify that it gets called.
本文标签: categoriesWPsaferedirect not working
版权声明:本文标题:categories - WP_safe_redirect not working 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742111659a2421284.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论