php - 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>
解决方案
我不知道为什么,但有时 Chrome 不像其他浏览器那样显示 favicon。尝试在你的头文件中添加 favicon.ico ,就像你对其他人所做的那样:
<link rel="icon" href="favicon.ico" type="image/x-icon" />
并将您的 favicon.ico 文件放在根目录中。因此,如果浏览器由于某种原因无法识别/获取图标,它们将favicon.ico
在您的根文件夹中采用默认设置。这样所有浏览器最终都会找到该图标
推荐阅读
- react-native - 按钮 onpress 不适用于自己的组件
- visual-studio-code - VSCode 中的 Gitlens 会根据任何文件更改自动开始 rebase
- java - 尝试使用 Apache POI 在 excel 中导出和着色行时出现异常
- python - Flask 博客,只希望一个用户能够发帖
- c# - 当我尝试运行此代码时,我得到“索引超出范围。必须是非负数且小于集合参数名称的大小”
- amazon-web-services - 为什么 AWS EMR EC2 实例的默认 spark.yarn.executor.memoryOverhead 设置为 18.75%
- c# - EF Core 5,子类实体上相同属性的不同转换
- debugging - 设置变量是否跨线程修改变量值?
- flutter - flutter_bloc 中的两个连续 BLOC
- java - 如何在多个数据库表中搜索值的最有效方式?