Skip to Content

post_tags()

Show the post tags metadata.

PHP March 25, 2020

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

Request or provide clarification »

Demo


Using post_meta:
Using individual Nebula post meta functions with options:
Other Nebula meta functions:
  • Functions
  • No EXIF data found

Source File

Located in /libs/Functions.php on line 586.

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
"nebula_post_tags_defaults"
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()){
        $defaults = apply_filters('nebula_post_tags_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'] ){
            $tag_list = get_the_tag_list('', ', ', '', $data['id']);
            if ( $tag_list ){
                $label = '';
                if ( $data['label'] === 'icon' ){
                    $tag_plural = ( count(get_the_tags()) > 1 )? __('tags', 'nebula') : __('tag', 'nebula');
                    $label = '<i class="nebula-post-tags-label fas fa-fw fa-' . $tag_plural . '"></i> ';
                } elseif ( $data['label'] === 'text' ){
                    $label = '<span class="nebula-post-tags-label">' . ucwords($tag_plural) . ' </span>';
                }

                if ( !$data['linked'] ){
                    $tag_list = strip_tags($tag_list);
                }

                if ( $data['string'] ){
                    return strip_tags($tag_list);
                }

                return '<span class="posted-in meta-item post-tags">' . $label . $tag_list . '</span>';
            }
        }
    }

Override

This function can not be short-circuited with an override filter. Request one?