Custom Redirects

Create and manage customized URL redirects.

PHP
/**
 * Snippet Name:     Custom Redirects
 * Snippet Author:   coding-bunny.com
 * Description:      Create and manage customized URL redirects.
 */

function cb_custom_redirects() {
    // Get the current URL path without the base domain
    $current_path = trim($_SERVER['REQUEST_URI'], '/');

    // Redirect to new page
    if ($current_path === 'about-us') {
        wp_redirect('https://www.mysite.com/about-me', 301);
        exit;
    }    
}

// Hook the redirect function to WordPress initialization
add_action('template_redirect', 'cb_custom_redirects');

How To Implement This Solution?

Leave a Reply

Your email address will not be published. Required fields are marked *

My Agile Privacy
This site uses technical and profiling cookies. You can accept, decline or customize cookies by pressing the desired buttons. By closing this policy you will continue without accepting.

Need help?

Choose one of the following options:

Powered by CodingBunny