AI Verified

Name

Redirect product category to page ID

About

Redirect a product category to a page ID

Language

PHP

Rating

Voted: 0 by 0 user(s)

How to Setup Snippet

Past in the code to your functions file and replace the following: $redirect_url = get_permalink( xx ); Change xx is the page ID you wish to redirect to $term = get_term_by( 'slug', 'my-category', 'product_cat' ); Change my-category to the category you wish to redirect from

Codevault

Thrive

Scroll down to see more snippets from this codevault.

Wordpress Compatability

The author has indicated that this snippet is compatable up to wordpress version: 6.1

Our AI bot has checked this snippet is compatable up to wordpress version: 6.1

Code Snippet Plugin Sync

Free & Pro

Download this snippet by clicking the download button, then head over to the Code Snippet Plugin settings in your wordpress admin dashboard, select the import menu then upload this file to import into your wordpress site.

Pro Only (Coming Soon)

You will be able to click a button and sync this snippet to your wordpress site automatically and from your dashboard manage all code snippets across all your wordpress sites that have the Code Snippets Pro plugin installed.

History

Last modified:

11/01/2023

Important Note

This snippet has the following status:

AI Verified

This snippet has been tested by our AI bot, see any comments below.

AI Bot Comments:

Found 0 vulnerabilities

Redirect product category to page ID

 
                    
1function redirect_photo_art_category() {
2 // Get the term object for the "my-category" product category
3 $term = get_term_by( 'slug', 'my-category', 'product_cat' );
4 
5 // Check if the current page is a product category archive for the "my-category" category
6 if( is_product_category( $term->term_id ) ) {
7 // Get the permalink for the page you want to redirect to
8 $redirect_url = get_permalink( 123 );
9 
10 // Redirect to the page
11 wp_redirect( $redirect_url );
12 exit;
13 }
14}
15 
16add_action( 'template_redirect', 'redirect_photo_art_category' );

0

Related Snippets

Please see some snippets below related to this snippet..

WooCommerce

AI Verified

0

Show Order Histories on User Profiles at the Backend

Added: 1 year ago

Last Updated: 1 year ago

WooCommerce

AI Verified

0

Hide shipping rates when free shipping is available

Added: 1 year ago

Last Updated: 1 year ago

WooCommerce

AI Verified

0

WooCommerce Remove Checkout Fields

Added: 1 year ago

Last Updated: 1 year ago

Other Snippets in this Codevault

These are some popular snippets from this users codevault..

WordPress Admin

AI Verified

0

Redirect user role on specific page

Added: 1 year ago

Last Updated: 1 year ago

This code will redirect a specific page based on the user role NOT being met.

WordPress Admin

AI Verified

0

Redirect by page ID

Added: 1 year ago

Last Updated: 1 year ago

Wordpress function to redirect one page id to another page id

WooCommerce

AI Verified

0

Redirect product category to page ID

Added: 1 year ago

Last Updated: 1 year ago

Redirect a product category to a page ID