Reputation: 139
In this e-commerce, its not necessary a single product page, is there a way to redirect these links to my homepage?
I have 3 products pages, /individual-box, /quarterly-box, /semester-box.
I tried something like this:
function redirect_to_home() {
if(!is_admin() && is_page('/product')) {
wp_redirect(home_url());
exit();
}
}
add_action('template_redirect', 'redirect_to_home');
Upvotes: 2
Views: 4205
Reputation: 254473
Try the following function:
add_action( 'template_redirect', 'product_redirection_to_home', 100 );
function product_redirection_to_home() {
if ( ! is_product() ) return; // Only for single product pages.
wp_redirect( home_url() ); // redirect home.
exit();
}
Code goes in function.php file of your active child theme (or active theme).
Upvotes: 4