温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

Wordpress如何设置公益404页面

发布时间:2021-10-09 09:22:37 来源:亿速云 阅读:169 作者:柒染 栏目:web开发

Wordpress如何设置公益404页面,针对这个问题,这篇文章详细介绍了相对应的分析和解答,希望可以帮助更多想解决这个问题的小伙伴找到更简单易行的方法。

Wordpress主题会自带404页面,如果需要替换成自定义的需要修改404.php页面

1.找到404页面设置的地方

一般在网站根目录下wp-yisu/themes/你的主题下,我的主题是sela,所以具体位置是wp-亿速/themes/sela/404.php

2.备份原页面修改成新的

备份原404.php页面并修改如下:

<?php

header("HTTP/1.0 404 Not Found");
include '404.html';
die();

?>

其中404.html内容如下:

<!DOCTYPE HTML>
<html>
<head>
   <meta charset="UTF-8" />
   <title>公益404</title>
</head>
<body>
<script type="text/javascript" src="//qzonestyle.gtimg.cn/qzone/hybrid/app/404/search_children.js" charset="utf-8" homePageUrl="https://minminmsn.com" homePageName="回到我的主页"></script>

</body>
</html>

3.测试访问效果

随意访问一个不存在的链接如minminmsn.com/404,希望她早日回家!

Wordpress如何设置公益404页面

4.补充搜索结果找不到页时设置404公益页面
修改wp-content/themes/sela/search.php将其中

<?php else : ?>

            <?php get_template_part( 'content', 'none' ); ?>

        <?php endif; ?>

改为

        <?php else : ?>

                        <?php header("HTTP/1.0 404 Not Found"); include '404.html'; die(); ?>

        <?php endif; ?>

完整内容如下:

<?php
/**
 * The template for displaying Search Results pages.
 *
 * @package Sela
 */

get_header(); ?>

    <section id="primary" class="content-area">
        <main id="main" class="site-main" role="main">

        <?php if ( have_posts() ) : ?>

            <header class="page-header">
                <h2 class="page-title"><?php printf( __( 'Search Results for: %s', 'sela' ), '<span>' . get_search_query() . '</span>' ); ?></h2>
            </header><!-- .page-header -->

            <?php /* Start the Loop */ ?>
            <?php while ( have_posts() ) : the_post(); ?>

                <?php get_template_part( 'content', 'search' ); ?>

            <?php endwhile; ?>

            <?php sela_content_nav( 'nav-below' ); ?>

        <?php else : ?>

                        <?php header("HTTP/1.0 404 Not Found"); include '404.html'; die(); ?>

        <?php endif; ?>

        </main><!-- #main -->
    </section><!-- #primary -->

<?php get_sidebar(); ?>
<?php get_footer(); ?>

关于Wordpress如何设置腾讯公益404页面问题的解答就分享到这里了,希望以上内容可以对大家有一定的帮助,如果你还有很多疑惑没有解开,可以关注亿速云行业资讯频道了解更多相关知识。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI