【发布时间】:2022-01-12 11:38:05
【问题描述】:
通常每当发生404错误时,都会显示模板中指定的404.php文件或页面。
例如
页面:产品 | page_id = 20
function custom_404(){
if (is_404()) {
global $wp_query;
$wp_query->is_404 = false;
status_header(200);
header("HTTP/1.1 200 OK");
$wp_query = new WP_Query(['page_id' => 20]);
get_header();
//method1
the_content();
//method2
echo do_shortcode( ' [my_shortcode] ' );
get_footer();
exit;
}
}
add_action('template_redirect', 'custom_404');
但问题是: 我的 WordPress 主题是 divi。模板未完全加载。 无需 js、css 代码即可加载页眉和页脚。
【问题讨论】: