【问题标题】:add html in wordpress label在 wordpress 标签中添加 html
【发布时间】:2014-03-21 20:31:05
【问题描述】:
我需要在 wordpress 中自定义一些菜单项的声音(不是全部)。
是否可以在标题标签中启用 html/css?
这是我的情况:
我只需要 ON 结果蓝光。
我尝试将 html 放在此标签中,但 html 未在该标签中运行。
有人知道是否可以在该标签中启用 html,也许使用 PHP?
非常感谢!
编辑:
tnx 这么多函数运行!
这儿存在一个问题...
我不需要所有菜单声音的功能,因为有些声音只有一个词。
你知道我怎么解决吗?
:)
【问题讨论】:
标签:
php
html
css
wordpress
【解决方案1】:
要对所有标题执行此操作,您可以将以下函数添加到您的 functions.php 文件中:
add_filter('the_title', function($title){
$parts = explode(' ', $title);
$parts[0] = '<span style="color:#42343;">'.$parts[0].'</span>';
return implode(' ', $parts);
});
最好添加一个类而不是样式,这样您就可以以不同的方式定位特定的标题,例如:
$parts[0] = '<span class="firstword">'.$parts[0].'</span>';
/*your style.css file*/
.home h2.title span.firstword {color: #333333;}
.about h2.title span.firstword {color: #42343;}
根据您的评论进行编辑,这就是您如何将其限制为仅影响包含多个单词的标题:
add_filter('the_title', function($title){
$parts = explode(' ', $title);
//if there are more than 1 word
if(count($parts)>1){
$parts[0] = '<span style="color:#42343;">'.$parts[0].'</span>';
}
return implode(' ', $parts);
});
【解决方案2】:
不建议在标题中添加 html。可以通过多种方式,但是会弄乱标题,因为它会使html显示在上面看起来不太好。
如果您仍然需要在标题上显示 html,我可以为您解决。给我留言,我会看看我能得到什么