404 redirect to random postID with a pool of selected posts
-
Hi, I was searching for a solution to randomly redirect all my 404 urls to a selected pool of posts, but can’t find any. I am only able to find this coding below which will redirect 404 urls to a specify post/page.
This is added to the function.php
/** 404 redirect */
add_action( ‘template_redirect’, ‘custom_redirect’, 1 );
function custom_redirect() {
$direction = get_permalink( 1 ); // Or whatever the page_id is …
if ( is_404() ) wp_redirect( $direction );
}What if I would like the 404 urls to randomly redirect among 3 posts (id 1,2,3), how should I modify the code to achieve this?
Any advise would be appreciated… Thanks..
- The topic ‘404 redirect to random postID with a pool of selected posts’ is closed to new replies.