• 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.