WordPress:网站图标未出现在自定义帖子类型或子页面上

Fre*_*ddy 5 php wordpress wordpress-theming

我有以下图标设置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>
Run Code Online (Sandbox Code Playgroud)

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

/父页面或父页面上,会出现我的图标。但在custom post types子页面或子页面上,我的图标没有显示。

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

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

index.php

get_header(); ?>

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

<?php get_footer();
Run Code Online (Sandbox Code Playgroud)

archive-knowledge.php

<?php get_header(); ?>

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

小智 0

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

<link rel="icon" href="favicon.ico" type="image/x-icon" />
Run Code Online (Sandbox Code Playgroud)

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