<?php
function my_cat_grabber() {
$categories = get_the_category();
if ($categories) {
// Initialize the HTML string for the category list
$html = '<ul class="post-cat_wrapper list--none" aria-label="categories">';
// Loop through each category, building the list items
foreach ($categories as $category) {
$category_link = get_category_link($category->term_id);
$category_name = $category->name;
// Escape the link and category name for security and build the HTML list item
$html .= '<li><a href="' . esc_url($category_link) . '">' .
esc_html($category_name) . '</a></li>';
}
// Close the unordered list
$html .= '</ul>';
// Return the complete HTML
return $html;
}
// If no categories are found, return an empty string
return '';
}
?>