Project category archive redirect code not working


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 );
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!

clayRay 4 months 0 Answers 13 views 0

Leave an answer