首页 > 解决方案 > WordPress:网站图标未出现在自定义帖子类型或子页面上

问题描述

我在以下网站图标设置header.php

<head>
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta charset="<?php bloginfo( 'charset' ); ?>">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="apple-touch-icon" sizes="180x180" href="<?php echo get_template_directory_uri()." /assets/build/favicon/apple-touch-icon.png "; ?>">
  <link rel="icon" type="image/png" sizes="32x32" href="<?php echo get_template_directory_uri()." /assets/build/favicon/favicon-32x32.png "; ?>">
  <link rel="icon" type="image/png" sizes="16x16" href="<?php echo get_template_directory_uri()." /assets/build/favicon/favicon-16x16.png "; ?>">
  <link rel="manifest" href="<?php echo get_template_directory_uri()." /assets/build/favicon/site.webmanifest "; ?>">
  <link rel="mask-icon" href="<?php echo get_template_directory_uri()." /assets/build/favicon/safari-pinned-tab.svg "; ?>" color="#5bbad5">
  <meta name="msapplication-TileColor" content="#da532c">
  <meta name="theme-color" content="#ffffff">
  <?php wp_head(); ?>
</head>

我将所有网站图标文件存储在assets/build/favicon.

/或父页面上,我的网站图标出现。但是在custom post types子页面上,我的图标没有出现。

文件路径是正确的(否则它们也不会显示在父页面上)。

为什么它不适用于自定义帖子类型页面或子页面?

index.php

get_header(); ?>

<?php while ( have_posts() ) : the_post(); ?>
    <?php the_content(); ?>
<?php endwhile; ?>

<?php get_footer();

archive-knowledge.php

<?php get_header(); ?>

<body class="knowledgeListing">
  <?php get_template_part('templates/parts/knowledge/level-one/listing'); ?>
  <?php get_footer(); ?>
</body>

标签: phpwordpresswordpress-theming

解决方案


我不知道为什么,但有时 Chrome 不像其他浏览器那样显示 favicon。尝试在你的头文件中添加 favicon.ico ,就像你对其他人所做的那样:

<link rel="icon" href="favicon.ico" type="image/x-icon" />

并将您的 favicon.ico 文件放在根目录中。因此,如果浏览器由于某种原因无法识别/获取图标,它们将favicon.ico在您的根文件夹中采用默认设置。这样所有浏览器最终都会找到该图标


推荐阅读