One way of doing it would be to modify your current code and add the links in there:
function category_name_shortcode() {
global $post;
$post_id = $post->ID;
$catName = "";
foreach((get_the_category($post_id)) as $category){
$catName .= '<a href="' . get_term_link($category) . '">' . $category->name . '</a>, ';
}
return $catName;
}
add_shortcode( 'post_category', 'category_name_shortcode' );
But there’s an easier way, because WP already has a way to obtain the list of categories with links (get_the_category_list
):
function category_name_shortcode() {
return get_the_category_list( ', ' );
}
add_shortcode( 'post_category', 'category_name_shortcode' );
Related Posts:
- do_shortcode based on _thumbnail_id
- Meta tags in shortcode
- Display post metadata: “title, category, author, date” with shortcode
- How to get_post_meta in a shortcode in excerpt on archive pages
- update_metadata() appends shortcode data for every page refresh
- Plugin Shortcode value in post
- Display post_meta in Shortcode
- Applying if (get_post_meta) to new shortcode
- What does extract( shortcode_atts( array( do?
- How do I escape a ‘]’ in a short code?
- Redirect function inside a Shortcode
- Remove wpautop from shortcode content / remove whitespace in buffering
- Shortcode in shortcode: How to append variable?
- How can i put an array as variable in shortcode_atts?
- Table of Contents with a shortcode
- Using action hooks inside of a shortcode
- Using shortcodes in PHP
- Remove width and height attributes from [gallery] output
- Is it possible not to define category on function.php and add the shortcode [shortcode cat=1] to display the products?
- Prevent add_shortcode from escaping a tag
- Shortcodes not working in an AJAX call
- Remove HTML content if attribute is not set / variable attributes
- Legacy Audio Shortcode
- Extending the Audio Shortcode
- How resource intensive is wp_register_script()?
- Convert shortcode into html form [closed]
- Numbering Image List in Gallery
- Register visits of my pages in wordpresss
- Is it possible to ignore the first Line Break in a preformatted Div from a shortcode?
- List monthy archives for specific year with wp_get_archives
- How can I included CSS to a page or a shortcode? [closed]
- Two Shortcodes in one page not working
- Call Shortcode inside another Shortcodes callback
- Creating a shortcode in a plugin that includes JS
- Compatibility of MathJax extension and JetPack [closed]
- Shortcode to delete post from front end
- How to parse shortcodes within returned content
- Hook WP_Embed run_shortcode
- Get Required Assets (JS, CSS etc) for post using REST API
- shortcode in snippet plugin not work
- AJAX and Shortcode with Parameters
- menu item to display the most recent post
- how to format / execute post content and shortcode?
- Documentation for adding a tinyMCE view for visual live preview of custom shortcode?
- How can I implement shortcode on click event
- Login form from shortcode doesn’t redirect after successful login
- How to list users by custom field?
- Form Shortcode not saving data to WP database
- Single post content custom order
- Adding a class to shortcode API
- Pass data back to TinyMCE from Thickbox
- Forcing WP to embedd a video when using a shortcode
- Shortcode for output of wp_get_archives displays at top of post
- How can I execute shortcode outside the loop?
- How to add “get_theme_mod” inside a shortcode?
- How to create shortcode to display perticular word from page title
- Shortcode is not returned correctly
- Echo HTML in custom shortcode
- How do I make a shortcode?
- Echoing Shortcode content inside the loop
- Short code inside the page not working in WordPress
- How can I list only custom shortcodes?
- Substite Category Slug in a Shortcode
- Add inline style to pages where shortcode was used
- add new attributes into existing shortcodes
- Anchor text in Short code →
- Theme Icons not visible on http://domain.com, works on http://ipaddress
- How to pass an array as attribute of shortcode to work properly shortcode parser?
- How to show an image via shortcode
- Use atributes of shortcode in get template part
- How to use multiple (or array) values in $content of shortcode?
- Is there any way to set the Featured image in wordpress post editor, using a Getty images embed code
- How to style inline code in block editor?
- Is it possible to capture the content outside/between shortcodes?
- How to use strip_shortcodes() from a spawned process?
- How to completely prevent WordPress from destroying/modifying my shortcode outputs?
- Term Description Echo or Return – display problems
- Same Shortcode not executing second time
- Check if Page=current user page via shortcode
- Is it inefficient to repeat a Shortcode 100 times on a page?
- tinymce custom button
- Running Filter or Shortcode Before Query Prevents Excerpt from Showing
- WordPress Payment link will not transform PHP vars into values
- Referring to site URL in shortcode argument
- Does a String Replacing script affect shortcode output?
- Shortcode for showing childpages
- How to create shortcode for auto login after registration
- How WordPress Displaying Shortcode In Post Content?
- Shortcode not accepting atts
- the_time function inside HTML dom parser
- Code auto escaping is not working when using short codes
- How to Convert Shortcode into a link?
- wp_register_script and wp_register_style when shortcode is used
- Wpautop stops working after get_the_excerpt
- Hook into existing shortcodes to manipulate the attributes?
- How can I hide the ACF shortcode when empty
- How to pass text input data to shortcode
- Using variable as shortcode parameter
- How to handle Ajax Calls, when using same shortcodes (with different parameters, e.g. ‘post-type’)?
- conditional shortcodes