Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function custom_redirect_404_to_blog() {
- if (is_404()) {
- // Get the current URI without the home URL
- $requested_uri = $_SERVER['REQUEST_URI'];
- // Check if the URI does not already start with '/blog/' to avoid infinite redirection
- if (substr($requested_uri, 0, 6) !== '/blog/') {
- // Construct the new URI by prepending '/blog' to the requested URI
- $new_uri = '/blog' . $requested_uri;
- // Perform the redirection to the new URI
- wp_redirect(home_url($new_uri), 301);
- exit;
- }
- }
- }
- add_action('template_redirect', 'custom_redirect_404_to_blog');
Advertisement
Add Comment
Please, Sign In to add comment