Title: Shortcode?
Last modified: August 22, 2016

---

# Shortcode?

 *  [kapow99504](https://wordpress.org/support/users/kapow99504/)
 * (@kapow99504)
 * [11 years, 7 months ago](https://wordpress.org/support/topic/shortcode-219/)
 * Did anything become of the ability to make a shortcode? I tried my had at it 
   but this seems to only work on posts that have a permalink category selected,
   those that only have one category to begin with don’t work
 *     ```
       //shortcode for primary category
       function primary_cat_shortcode($atts) {
        global $post;
         $cat_id = get_post_meta( $post->ID , '_category_permalink', true );
            if ( $cat_id != null ) {
       	$cat = get_category( $cat_id );
       	$category_link = get_category_link( $cat_id );
       	$category_name = $cat->name;
            } else {
       	$cat = get_the_category();
       	$category_link = get_category_link( $category->term_id );
       	$category_name = $cat[0]->cat_name;
            }
            $primary_cat_link= '<a href="'.$category_link.'">'.$category_name.'</a>';
        return $primary_cat_link;
       }
       add_shortcode('primary_cat', 'primary_cat_shortcode');
       ```
   

The topic ‘Shortcode?’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/wp-category-permalink_161616.svg)
 * [WP Category Permalink](https://wordpress.org/plugins/wp-category-permalink/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/wp-category-permalink/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/wp-category-permalink/)
 * [Active Topics](https://wordpress.org/support/plugin/wp-category-permalink/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wp-category-permalink/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wp-category-permalink/reviews/)

 * 0 replies
 * 1 participant
 * Last reply from: [kapow99504](https://wordpress.org/support/users/kapow99504/)
 * Last activity: [11 years, 7 months ago](https://wordpress.org/support/topic/shortcode-219/)
 * Status: not resolved