Usage
PHP
nebula()->post_tags($icon)
Parameters
$options
(Optional) (Array) An array of options
Default: None
Parameter Notes
id
The post ID to get tags for
Default: current post
label
Whether to show the tag “icon”, “text”, or not
Default: icon
force
Override the Customizer setting
Default: false
string
Return a string with no markup
Default: false
Demo
Using post_meta:
Using individual Nebula post meta functions with options:
Other Nebula meta functions:
Source File
Located in /libs/Functions.php on line 829.
1 Hook
Find these filters and actions in the source code below to hook into them. Use do_action() and add_filter() in your functions file or plugin.
Filters
"pre_nebula_post_tags"Need a new filter hook? Request one here.
Actions
This function has no action hooks available. Request one?
PHP
public function post_tags($options=array()){
$override = apply_filters('pre_nebula_post_tags', null, $options);
if ( isset($override) ){return $override;}
$defaults = array(
'id' => get_the_ID(),
'label' => 'icon', //"icon" or "text"
'linked' => true, //Link to tag archive
'force' => false,
'string' => false, //Return a string with no markup
);
$data = array_merge($defaults, $options);
if ( get_theme_mod('post_tags', true) || $data['force'] ){
$the_tags = get_the_tags($data['id']);
if ( $the_tags && is_array($the_tags) ){
$label = '';
$tag_plural = ( count($the_tags) > 1 )? __('tags', 'nebula') : __('tag', 'nebula');
if ( $data['label'] === 'icon' ){
$label = '<i class="nebula-post-tags-label fa-solid fa-' . $tag_plural . '"></i> ';
} elseif ( $data['label'] === 'text' ){
$label = '<span class="nebula-post-tags-label">' . ucwords($tag_plural) . ' </span>';
}
//If we just want comma-separated plain text
if ( $data['string'] ){
$tag_names = array_map(fn($tag) => $tag->name, $the_tags);
return implode(', ', $tag_names);
}
//Otherwise output individual span tags
$tag_items = '';
$tag_count = count($the_tags);
$current = 0;
foreach ( $the_tags as $tag ){
$tag_name = esc_html($tag->name);
$current++;
if ( $data['linked'] ){
$tag_link = get_tag_link($tag->term_id);
$tag_items .= '<span role="listitem"><a href="' . esc_url($tag_link) . '">' . $tag_name . '</a></span>';
} else {
$tag_items .= '<span role="listitem">' . $tag_name . '</span>';
}
if ( $current < $tag_count ) {
$tag_items .= ', ';
}
}
return '<span class="posted-in meta-item post-tags" role="list">' . $label . $tag_items . '</span>';
}
}
}
Override
To override this PHP function, use this hook in your child theme or plugin ("my_custom" can be changed):
PHP
add_filter('pre_nebula_post_tags', 'my_custom_post_tags', 10, 2); //The last integer must be 1 more than the actual parameters
function my_custom_post_tags($null, $options){ //$null is required, but can be ignored
//Write your own code here
return true; //Return true to prevent the original function from running afterwords
}
You can completely disable this PHP function with a single line actions:
PHP
add_filter('pre_nebula_post_tags', '__return_false');