首页 问答 正文

如何为wordpress主题添加自定义的404页面?

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

要为WordPress主题添加自定义的404页面,可以按照以下步骤进行操作:

  1. 在您的主题文件夹中创建一个新的文件,命名为404.php,这将是您的自定义404页面的模板文件。
  2. 打开404.php文件,并根据您的设计和需求添加所需的HTML和CSS代码。

以下是一个简单的示例404.php文件的代码:

<?php get_header(); ?>

<div id="primary" class="content-area">
    <main id="main" class="site-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.', 'your-theme-text-domain' ); ?></h1>
            </header>

            <div class="page-content">
                <p><?php esc_html_e( 'It looks like nothing was found at this location.', 'your-theme-text-domain' ); ?></p>
                <p><?php esc_html_e( 'Please try searching or use the navigation menu to navigate to a different page.', 'your-theme-text-domain' ); ?></p>
            </div>
        </section>
    </main>
</div>

<?php get_footer(); ?> 
  1. 保存并上传您的404.php文件到您的主题文件夹中。
  2. 确保你的WordPress后台启用了您的自定义主题。
  3. 现在,在浏览器中访问一个不存在的页面,将会显示您自定义的404页面。
大家谈论
    我的见解