How to show Custom Post Type name in category archive? I already tried with shortcode and this snippet, but it returns an empty string. I want the CPT name (plural label) or if that’s hard to do: the Post type key. Cwicly can do so much, it feels like I miss something in the dynamic side of things… Thanks!
function display_current_post_type_shortcode() {
// Check if it's a category archive
if (is_category() && is_archive()) {
// Get the current category object
$category = get_queried_object();
// Check if the category has a custom post type associated with it
if ($category && isset($category->taxonomy) && isset($category->term_id)) {
$post_type = get_taxonomy($category->taxonomy)->object_type;
if (!empty($post_type)) {
$post_type_labels = get_post_type_object($post_type[0])->labels;
// Return the content with the current post type
return '<p>Current Custom Post Type in Category Archive: ' . esc_html($post_type_labels->singular_name) . '</p>';
}
}
}
// Return an empty string if not a category archive
return 'hier CPT naam test vanuit shortcode';
}
// Register the shortcode
add_shortcode('current_post_type', 'display_current_post_type_shortcode');```