The first way to redirect a WordPress page without redirecting plugins you need to add some code snippets to the functions.php the main WordPress functions file that is located in your WordPress theme.
Inside your WordPress theme, you should locate this file that is named functions.php.
This file adds all the functions to your WordPress theme and by extension your WordPress site.
Open the functions.php file and add the following code replacing the ‘about’ with your respective page which you want to redirect the users to.
Redirect a WordPress Page Without Plugins (WP_Redirect)
add_action('template_redirect', 'redirect_to_home_from_about_page'); function redirect_to_home_from_about_page() { if( is_page('about')) { wp_redirect(home_url()); exit(); } }
This code checks if the user is on the About page and if they are on the About page they are redirected to the home page.
You can change this to check any other page by changing the ‘about’ string that checks if the user is on the About page. For example, we can alter the code and check if the user is on the ‘contact’ page as follows :
add_action('template_redirect', 'redirect_to_home_from_about_page'); function redirect_to_home_from_about_page() { if( is_page('contact')) { wp_redirect(home_url()); exit(); } }
Redirect a WordPress Page Without Plugins (HTACCESS)
An alternative way to redirect a WordPress page without using plugins is adding a redirect rule to the htacess file that is located in the root of your WordPress installation.
If you cannot locate this file, consider checking the permissions since the file is mostly hidden on your server. Open the file and add the following code replacing the URLs for the old and new pages respectively :
RewriteEngine On Redirect 301 /old-post/ http://yoursite.com/new-post/
Joe is an experienced full-stack web developer with a decade of industry experience in the LAMP & MERN stacks, WordPress, WooCommerce, and JavaScript – (diverse portfolio). He has a passion for creating elegant and user-friendly solutions and thrives in collaborative environments. In his spare time, he enjoys exploring new tech trends, tinkering with new tools, and contributing to open-source projects. You can hire me here for your next project.
Similar Articles
- How to Check If Plugin is Active In WordPress [ 3 WAYS ]
- How to Create Custom Query Pagination In WordPress With an Example
- How to Set a Featured Image in WordPress Gutenberg & Classic Editor
- How to Add Text Before the Price in WooCommerce » Add Text Before Price
- How to Skip Cart and Redirect to Checkout Page WooCommerce
- How to Change Return to Shop Link in Woocommerce
- How to Redirect to Cart after Login in WooCommerce
- How to Get Post ID by Slug in WordPress With a Practical Example
- How to Remove Has Been Added to Your Cart Message WooCommerce
- How to Hide Admin Bar for WooCommerce Customers or By User Roles
- How to Redirect Users after Successful Login in WordPress without Using a Plugin
- How to Redirect User If Not Logged in WordPress » Page Redirect
- How to Check if a User is Logged In in WordPress
- How to Display Category Names in WordPress Using a Practical Example
- Change Proceed To Checkout Text In WooCommerce
- How to Get Order ID In Woocommerce
- How to Deactivate Jetpack Mobile Theme
- How to Add Active Navigation Class Based on URL
- How to Hide a Product in WooCommerce or Hide Products by Category or Roles
- How to Change the WooCommerce ‘Added to Cart’ Notice
Comments are closed.