{"id":5382519,"date":"2014-10-12T23:12:47","date_gmt":"2014-10-12T23:12:47","guid":{"rendered":"https:\/\/wordpress.org\/support\/topic\/shortcode-219\/"},"modified":"2016-08-22T03:23:19","modified_gmt":"2016-08-22T03:23:19","slug":"shortcode-219","status":"closed","type":"topic","link":"https:\/\/wordpress.org\/support\/topic\/shortcode-219\/","title":{"rendered":"Shortcode?"},"content":{"rendered":"<p>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&#8217;t work<\/p>\n<pre><code>\/\/shortcode for primary category\nfunction primary_cat_shortcode($atts) {\n global $post;\n  $cat_id = get_post_meta( $post-&gt;ID , &#039;_category_permalink&#039;, true );\n     if ( $cat_id != null ) {\n\t$cat = get_category( $cat_id );\n\t$category_link = get_category_link( $cat_id );\n\t$category_name = $cat-&gt;name;\n     } else {\n\t$cat = get_the_category();\n\t$category_link = get_category_link( $category-&gt;term_id );\n\t$category_name = $cat[0]-&gt;cat_name;\n     }\n     $primary_cat_link= &#039;&lt;a href=&quot;&#039;.$category_link.&#039;&quot;&gt;&#039;.$category_name.&#039;&lt;\/a&gt;&#039;;\n return $primary_cat_link;\n}\nadd_shortcode(&#039;primary_cat&#039;, &#039;primary_cat_shortcode&#039;);<\/code><\/pre>\n","protected":false},"template":"","class_list":["post-5382519","topic","type-topic","status-closed","hentry"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/5382519","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic"}],"about":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/types\/topic"}],"version-history":[{"count":0,"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/5382519\/revisions"}],"wp:attachment":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/media?parent=5382519"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}