【发布时间】:2021-08-15 21:45:13
【问题描述】:
我在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>
【问题讨论】:
-
您是否真的在自定义帖子类型和子页面模板中调用了
header.php文件?有时很容易忘记! -
嗨@Ruvee - 我可以确认我的自定义帖子类型正在使用
get_header()。我的所有页面都使用get_header()(通过index.php),但它没有解释为什么在父页面上显示图标图标,但在子页面上没有? -
在自定义帖子类型页面上,您没有看到任何来自 header.php 的代码显示在源代码中?你使用主题生成器或类似的东西吗?还是购买带有自定义选项的主题?
-
@Freddy 我只是想知道您是否知道 WordPress 4.3+ 中的 site icon feature?如果是这样,你为什么不直接使用它?还是您已经尝试过并且发生了同样的问题?我们可以看看你的
index.php模板吗?您是否对所有页面(单个页面、帖子、CPT、类别等)使用单个index.php文件? -
嗨@SallyCJ - 是的,我知道通过
customizer的favicon 选项。通过此处上传站点图标对我来说产生了相同的结果,该图标只会显示在顶级页面(而不是子页面)上,并且不会出现在custom post types上。我更新了我的问题以展示index.php和archive-knowledge.php,这是我的custom post types之一。
标签: php wordpress wordpress-theming