首页 问答 正文

如何在wordpress中设置404页面?

注册会员 / 悠然自学 / 2023-07-11/ 浏览 125 次

在WordPress中设置404页面,可以按照以下步骤:

  1. 在主题文件夹中创建一个新的404.php文件。可以通过FTP或者服务器文件管理器进入WordPress主题的文件夹,找到当前正在使用的主题文件夹。
  2. 在404.php文件中添加自定义的404页面内容。示例如下:
<?php get_header(); ?>

<div id="primary" class="content-area">
    <main id="main" class="site-main" role="main">
        <section class="error-404 not-found">
            <header class="page-header">
                <h1 class="page-title"><?php esc_html_e( 'Oops! That page can&rsquo;t be found.', 'text-domain' ); ?></h1>
            </header>
            <div class="page-content">
                <p><?php esc_html_e( 'It looks like nothing was found at this location. Maybe try a search?', 'text-domain' ); ?></p>

                <?php get_search_form(); ?>
            </div>
        </section>
    </main>
</div>

<?php get_footer(); ?> 
  1. 保存并上传404.php文件到主题文件夹中。
  2. 刷新你的WordPress网站,打开一个不存在的页面,应该会显示自定义的404页面。

以上示例代码中,会显示一条错误信息和一个搜索表单,让用户可以搜索其它内容。你可以根据需要进行修改和自定义404页面的内容样式。

大家谈论
    我的见解