简体   繁体   中英

Need help regarding wordpress functions.php code which is used for redirections

I would highly appreciate it if you could help me with inserting the redirection code. I am using the following script to redirect the old website to the new one on the same post path. I insert that script in Wordpress functions.php and the script works perfectly in redirecting.

I want that script to be executed after 5 seconds delay.. i mean the visitor while reading the post redirects to the same post on another website after 5 seconds, I meant to say the user stay on the same post page for 5 seconds before redirecting to the other website's same post.

EXAMPLE: www.MyWebSite.com/Post123 visitor stay on the /Post123 for 5 seconds and then redirects to www.OtherWebSite.com/Post123

please help .. following is the code. I would highly appreciate it if you could do me a favor by responding on my question by modifying the code I have given below so I can copy and paste it into wordpress editor functions.php.. Thanks a lot.

 function redirect_posts() {
    global $post;
    if ($post->post_type=='post') {
        return header('location:https://www.MYWEBSITE.com/'.$post->post_name);
    }
}
add_action('wp', 'redirect_posts');

I read your question and i suggested can you use Redirection plugin.

This plugin is used for 301 redirects and many conditional causes.

You can read plugin documentation for here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM