• Hello,

    Is there any code available to replace a category page link with homepage link everywhere on website ?

    I don’t want code to redirect a category page to homepage, I am looking for code that will redirect a particular category page link with homepage link everywhere on my wordpress site.

    Thanks in advance

    • This topic was modified 1 year, 11 months ago by manav kalra.
Viewing 1 replies (of 1 total)
  • Hey, you may try this:
    To redirect a specific category page link to your homepage on a WordPress site, you can use the following code in your theme’s functions.php file:

    
    add_action( 'template_redirect', 'redirect_category_page' );
    function redirect_category_page() {
      if ( is_category( 'category-slug' ) ) {
        wp_redirect( home_url(), 301 );
        exit;
      }
    }
    

    This code uses the ‘template_redirect’ action hook to redirect the user when they visit the category page with the slug “category-slug”. The wp_redirect function is used to redirect the user to the homepage, and the 301 status code indicates that this is a permanent redirect.

    Note that you will need to replace “category-slug” with the actual slug of the category page that you want to redirect. You can also use the is_category function to check for other conditions, such as the ID or name of the category.

    Keep in mind that this code will only work for category pages, and will not affect other types of pages or links on your site. If you want to redirect other types of pages or links, you may need to use a different approach.
    Hope it works.

Viewing 1 replies (of 1 total)
  • The topic ‘How to replace category page link with homepage page’ is closed to new replies.