Skip to content

Instantly share code, notes, and snippets.

@dantetesta
Last active September 21, 2023 13:29
Show Gist options
  • Save dantetesta/33f73b2dd5f245a19e0796fda6ee20d9 to your computer and use it in GitHub Desktop.
Save dantetesta/33f73b2dd5f245a19e0796fda6ee20d9 to your computer and use it in GitHub Desktop.
<?php
function cpt_posttype_name_shortcode($atts) {
// Atributos padrão
$a = shortcode_atts(array(
'cpt' => 'post', // 'post' é o valor padrão caso nenhum slug seja fornecido
), $atts);
$post_type_object = get_post_type_object($a['cpt']);
if ($post_type_object) {
return esc_html($post_type_object->labels->name);
} else {
return 'Post Type não encontrado';
}
}
add_shortcode('cpt_posttype_name', 'cpt_posttype_name_shortcode');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment