WordPress Q&As Logo
WordPress Q&As Part of the Q&A Network
Q&A Logo

How can I redirect a specific page in WordPress using code?

Asked on Sep 01, 2025

Answer

To redirect a specific page in WordPress using code, you can add a custom function to your theme's `functions.php` file. This involves using the `template_redirect` action hook to check for the specific page and then execute the redirect.
<!-- BEGIN COPY / PASTE -->
    add_action('template_redirect', 'custom_redirect_specific_page');
    
    function custom_redirect_specific_page() {
        if (is_page('your-page-slug')) { // Replace 'your-page-slug' with the actual page slug
            wp_redirect('https://example.com/new-page-url'); // Replace with the URL you want to redirect to
            exit;
        }
    }
    <!-- END COPY / PASTE -->
Additional Comment:
  • Ensure you replace 'your-page-slug' with the slug of the page you want to redirect.
  • Replace 'https://example.com/new-page-url' with the full URL of the destination page.
  • Always back up your `functions.php` file before making changes to avoid potential issues.
  • Test the redirect to ensure it works as expected after implementing the code.
✅ Answered with WordPress best practices.

← Back to All Questions
The Q&A Network