Created
January 2, 2020 22:32
-
-
Save evanfraser/5df9a260805a0d3208f89d07c6b22b09 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Get Post Category | |
* | |
* Shortcode: [post_category] | |
*/ | |
function shortcode_post_category($atts=array()) { | |
// get taxonomy by post type | |
$tax = get_object_taxonomies(get_post_type()); | |
// get the categories of the taxonomy | |
$cats = get_the_terms($post->ID, $tax[0]); | |
$result = ''; | |
foreach ($cats as $cat) { | |
$result = $cat->name; | |
return $result; | |
} | |
return $result; | |
} | |
add_shortcode('post_category', 'shortcode_post_category'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment