我目前有以下内容,试图避免在没有标签的情况下显示标签(本例中的图标),但图标会继续显示。有什么想法吗?
<?php if ( is_singular() && function_exists(\'the_tags\') ) : ?>
<p><i class="icon-tags"></i><?php the_tags(\'\', \', \', \' \'); ?></p>
<?php endif; ?>
我目前有以下内容,试图避免在没有标签的情况下显示标签(本例中的图标),但图标会继续显示。有什么想法吗?
<?php if ( is_singular() && function_exists(\'the_tags\') ) : ?>
<p><i class="icon-tags"></i><?php the_tags(\'\', \', \', \' \'); ?></p>
<?php endif; ?>
获取string 标签的值,并且仅当有标签时才打印:
$tags = get_the_tag_list(\'\', \', \', \' \');
if ( "" !== trim( $tags ) )
{
echo "<p><i class=\'icon-tags\'></i>$tags</p>";
}
您还可以将html添加到的“before”参数中the_tags()
例如,将整个代码缩减为一行:
<?php if ( is_singular() ) the_tags(\'<p><i class="icon-tags"></i>\', \', \', \'</p>\'); ?>`
我想收拾一下<script> WordPress生成的标签为HTML5生成更多语义输出。您已经可以为<style> 将使用此代码的标记附加到style_loader_tag 过滤器://clean up the default WordPress style tags add_filter(\'style_loader_tag\', \'clean_style_tag\'); function clean_style_tag($input) {