How to Redirect Automatic Error 404 Page To Homepage With JavaScript
How to Redirect Automatic Error 404 Page To Homepage With JavaScript - It could be that a blog has an error page 404 or a page not found. Usually the page has been deleted or by other causes such as writing errors in posting URLs, and others.
Usually on a blog or web to create a page or landing page specifically for error 404 pages by giving a statement that the destination page has been deleted or no longer exists. The rest is given a button to the homepage or provided a search box to search for the desired post again.
Now this time I will give a trick to automatically redirect or redirect the error 404 page to the compilation so that visitors do not need to click the button to the homepage. Actually, posts like this have a lot on Google, but there are some that are still difficult to implement because the script does not work in some templates, especially templates that use conditional tags for error 404 pages. So if you want to try it, you can immediately follow the following steps this.
To automatically redirect or redirect the 404 error page to the compilation, actually it's very easy to simply copy the code below, then put the code before the code </body> or <!--</body>--> </body>
1. For nonAMP blogs
The above code will automatically redirect the error 404 page to the homepage after 8 seconds, so that visitors can still read the message on the error 404 page, you can set / replace the 8000 number to set the waiting time. 1 second = 1000.
If you want to directly redirect, use the following code.
Or
2. For AMP Blogs
As for blogs that use mobile URL mobile?m=1 as AMP, use the following code that will only apply to desktop URL.
Or
3. WordPreess
This can also be used in WordPress, please save this code in the 404.php section at the bottom.
or
Thus tips that I can share about tips on How to Redirect Automatic Error 404 Page To Homepage With JavaScript. Hopefully with these brief tips, it can be useful and useful for all of you. Good luck.
Usually on a blog or web to create a page or landing page specifically for error 404 pages by giving a statement that the destination page has been deleted or no longer exists. The rest is given a button to the homepage or provided a search box to search for the desired post again.
Now this time I will give a trick to automatically redirect or redirect the error 404 page to the compilation so that visitors do not need to click the button to the homepage. Actually, posts like this have a lot on Google, but there are some that are still difficult to implement because the script does not work in some templates, especially templates that use conditional tags for error 404 pages. So if you want to try it, you can immediately follow the following steps this.
How to Redirect Automatic Error 404 Page To Homepage With JavaScript
To automatically redirect or redirect the 404 error page to the compilation, actually it's very easy to simply copy the code below, then put the code before the code </body> or <!--</body>--> </body>
1. For nonAMP blogs
<b:if cond='data:blog.pageType in {"error_page"}'>
<script>
setTimeout(function () {window.location.replace("<data:blog.homepageUrl/>");
}, 8000); //will call the function after 8 seconds.
</script>
</b:if>
The above code will automatically redirect the error 404 page to the homepage after 8 seconds, so that visitors can still read the message on the error 404 page, you can set / replace the 8000 number to set the waiting time. 1 second = 1000.
If you want to directly redirect, use the following code.
<b:if cond='data:blog.pageType in {"error_page"}'>
<script>
setTimeout(function () {window.location.replace("<data:blog.homepageUrl/>");
});
</script></b:if>
Or
<b:if cond='data:blog.pageType in {"error_page"}'>
<script>
window.location.replace("<data:blog.homepageUrl/>");
</script></b:if>
2. For AMP Blogs
As for blogs that use mobile URL mobile?m=1 as AMP, use the following code that will only apply to desktop URL.
<b:if cond='data:blog.pageType in {"error_page"} and data:blog.isMobileRequest == "false"'>
<script>
setTimeout(function () {window.location.replace("<data:blog.homepageUrl/>");
}, 8000); //will call the function after 8 seconds.
</script></b:if>
Or
<b:if cond='data:blog.pageType in {"error_page"} and data:blog.isMobileRequest == "false"'>
<script>
setTimeout(function () {window.location.replace("<data:blog.homepageUrl/>");
});
</script></b:if>
3. WordPreess
This can also be used in WordPress, please save this code in the 404.php section at the bottom.
<script>
setTimeout(function () {window.location.replace("<?php echo home_url('/'); ?>");
}, 8000); //will call the function after 8 seconds.
</script>
or
<script>
setTimeout(function () {window.location.replace("<?php echo home_url('/'); ?>");
});
</script>
Thus tips that I can share about tips on How to Redirect Automatic Error 404 Page To Homepage With JavaScript. Hopefully with these brief tips, it can be useful and useful for all of you. Good luck.
Post a Comment for "How to Redirect Automatic Error 404 Page To Homepage With JavaScript"
Provide comments relevant to the posted articles and provide critiques and suggestions for the progress of the blog