shortcode – Help to display the current categories and tags of a post

Question

I am using a shortcode to try to display the tags and categories of a post.
Specifically, this is a portfolio post, so when a user visits a post they will see the associated categories and tags. example here

My shortcode is pulling all portfolio-categorys or portfolio-tags, not just those of the current post.

<?php
class ListCategories{
  static function list_categories($atts, $content = null) {
    $atts = shortcode_atts(
      array(
        'child_of'            => 0,
        'current_category'    => 0,
        'depth'               => 0,
        'echo'                => 1,
        'exclude'             => '',
        'exclude_tree'        => '',
        'feed'                => '',
        'feed_image'          => '',
        'feed_type'           => '',
        'hide_empty'          => 1,
        'hide_title_if_empty' => false,
        'hierarchical'        => 1,
        'include'             => '',
        'number'              => null,
        'order'               => 'ASC',
        'orderby'             => 'name',
        'pad_counts'          => 0,
        'show_count'          => 0,
        'show_option_all'     => '',
        'show_option_none'    => __( 'No categories' ),
        'style'               => 'list',
        'taxonomy'            => 'category',
        'title_li'            => __( 'Categories' ),
        'use_desc_for_title'  => 1,
        'walker'              => null,
      ), $atts
    );

    ob_start();
    wp_list_categories($atts);
    $output = ob_get_contents();
    ob_end_clean();
    return $output;
  }
}

add_shortcode( 'categories', array('ListCategories', 'list_categories') );

0
Georgeand 6 months 2022-02-23T18:32:52-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse