要调整WordPress中的404页面,可以按照以下步骤进行:
<?php get_header(); ?>
<main class="site-main">
<section class="error-404 not-found">
<header class="page-header">
<h1 class="page-title"><?php _e( 'Oops! That page can’t be found.', 'mytheme' ); ?></h1>
</header>
<div class="page-content">
<p><?php _e( 'It looks like nothing was found at this location. Maybe try one of the links below or a search?', 'mytheme' ); ?></p>
<?php get_search_form(); ?>
<?php the_widget( 'WP_Widget_Recent_Posts' ); ?>
<div class="widget widget_categories">
<h2 class="widget-title"><?php _e( 'Most Used Categories', 'mytheme' ); ?></h2>
<ul>
<?php
wp_list_categories( array(
'orderby' => 'count',
'order' => 'DESC',
'show_count' => 1,
'title_li' => '',
'number' => 10,
) );
?>
</ul>
</div>
<?php
/* translators: %1$s: smiley */
$archive_content = '<p>' . sprintf( __( 'Try looking in the monthly archives. %1$s', 'mytheme' ), convert_smilies( ':)' ) ) . '</p>';
the_widget( 'WP_Widget_Archives', 'dropdown=1', "after_title=</h2>$archive_content" );
?>
<?php the_widget( 'WP_Widget_Tag_Cloud' ); ?>
</div>
</section>
</main>
<?php get_footer(); ?>
function mytheme_404_page() {
if ( is_404() ) {
include( get_template_directory() . '/404.php' );
exit();
}
}
add_action( 'template_redirect', 'mytheme_404_page' );
以上代码的作用是,如果当前页面是404页面,则自动使用自定义的404页面。
最后,需要注意的是,使用自定义404页面可能对SEO产生影响,需要根据具体情况进行调整,以避免不必要的影响。