admin管理员组文章数量:1323157
I have a 404 page in my theme but I am not using that page. I have created a new 404 page in WordPress using wpbakery page builder. I need to know how can I redirect users on the new 404 page without a plugin?
I have a 404 page in my theme but I am not using that page. I have created a new 404 page in WordPress using wpbakery page builder. I need to know how can I redirect users on the new 404 page without a plugin?
Share Improve this question asked Aug 28, 2020 at 5:51 Naren VermaNaren Verma 2491 gold badge6 silver badges19 bronze badges 2- Do you mean you want to use your new wpbakery page as the 404 page? I'm not sure implementing that as a redirect is a good idea as search engines etc. will see the redirect status code and not the missing page. – Rup Commented Aug 28, 2020 at 8:56
- 1 The term "redirect" is commonly misused in this context. You probably mean you want to serve your new 404 page instead of the current one. (A "redirect" implies an HTTP 3xx external redirect - which is generally a bad idea when serving an error document, as @Rup has already pointed out.) – MrWhite Commented Aug 28, 2020 at 9:27
1 Answer
Reset to default 1You can assign the 404.php as a template to your custom 404 page created with the page builder.
You would need to edit the 404.php to something like this:
<?php
/**
* Template Name: 404
*/
get_header();
$query = new WP_Query([
'posts_per_page' => 1,
'post_type' => 'page',
'meta_key' => '_wp_page_template',
'meta_value' => basename(__FILE__)
]);
if ($query-> have_posts()) {
echo do_shortcode($query->post->post_content)
}
get_footer();
This way you would load the contents of your custom 404 page into the 404.php template.
You probably need to adapt the code above to the actual HTML structure of your theme.
本文标签: htaccessHow can I redirect users on the new 404 page without plugin
版权声明:本文标题:htaccess - How can I redirect users on the new 404 page without plugin? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742142167a2422628.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论