我使用Divi为自定义404页构建布局。我使用这个插件https://wordpress.org/plugins/redirect-404-error-page-to-homepage-or-custom-page/将404错误重定向到这个页面。它可以工作,但是当我运行像尖叫青蛙这样的工具时,它会将破页作为301重定向返回,我猜这是应该的。
然而,我希望我的404.php模板包含我构建的页面,这样我仍然可以准确地跟踪404错误。我在想这样的事情:
#404.php我试过的是:
//Redirect to our custom 404 page
function wf_404(){
//Check if custom 404 page exists to protect against infinite loop
if (is_404() && get_page_by_path('/404-page/', OBJECT)){
wp_safe_redirect(get_site_url() . '/404-page/', 404);
exit;
}
}
add_action('get_header', 'wf_404');这给了我一个普通浏览器404错误。
发布于 2019-02-13 18:13:27
您可以将php/html从singular.php/page.php复制到404.php。然后,按照echo apply_filters('the_content', $page->post_content);的建议,用mrben522替换content循环。
以法典的代码为例,
post_content); // This is where the magic (should) happen
?>https://wordpress.stackexchange.com/questions/328611
复制相似问题