admin管理员组文章数量:1332377
I would like to place an icon in the post title of every article from the category "plus".
This is my attempt for function.php, but it doesn't work that way. Can someone please give me some advice?
if (has_category( 'plus' )
return;
echo '<style>
.entry-title:before {
content: url(".png");
margin-right: 10px;
}
</style>';
}
I would like to place an icon in the post title of every article from the category "plus".
This is my attempt for function.php, but it doesn't work that way. Can someone please give me some advice?
if (has_category( 'plus' )
return;
echo '<style>
.entry-title:before {
content: url("https://testfeld051.magazin.de/wp-content/uploads/2020/05/C-Plus.png");
margin-right: 10px;
}
</style>';
}
Share
Improve this question
asked Jul 2, 2020 at 15:07
tizian_72tizian_72
111 bronze badge
0
1 Answer
Reset to default 1This will depend on how your theme is structuring the templates for single.php (individual post view) but I'll show you what to look for and how to apply via CSS.
So from a theme I'm working on, this is where the category gets included in the post:
<article id="post-3417" class="post-3417 post type-post status-publish format-standard hentry category-plus">
.
The last class in the <article>
element is category-plus
. So I want to target that.
My CSS would then look like this:
article.category-plus > header.entry-header > .entry-title:before {
content: url('wp-content/uploads/2020/05/C-Plus.png');
display: block;
float: right;
margin-right: 10px;
width: 1em;
height: 1em;
}
You'll have to check the source code of the one of the pages you want to add this to (because your theme is different than the one I'm currently working on, so it'll probably have a different set-up), locate where in the entry it specifies the category and then use that information to properly structure your CSS selector.
You can adjust sizing, positioning, etc, as needed - but this is far easier and standard than writing to your functions.php
to include a single CSS style rule.
本文标签: postsAdd iconbadge next to posttitle of specific category
版权声明:本文标题:posts - Add iconbadge next to posttitle of specific category 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742297740a2449070.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论