Archived topic
Remove Archive Title on Custom Post Type
5 replies · Started by Rostyslav on February 15, 2023
Hello,
I have created a CPT and added a design element to disable a title in Archive and Taxonomy but it doesnt work.
How can I remove that titles. I want to create a custom layout for that Archives.
Thanks
Hi there,
try this PHP Snippet:
add_action('wp', function(){
if ( is_post_type_archive( 'my_custom_post_type' ) ) {
remove_action( 'generate_archive_title', 'generate_archive_title' );
}
});
change the my_custom_post_type to your CPT slug
Hello!
How can I also add the CPT taxonomies (categories in CPT) in that php?
I also want to remove taxonomy title.
Thanks
You can is the is_tax template tag:
https://developer.wordpress.org/reference/functions/is_tax/
eg,
add_action('wp', function(){
if ( is_post_type_archive( 'my_custom_post_type' ) || is_tax('my_tax_slug') ) {
remove_action( 'generate_archive_title', 'generate_archive_title' );
}
});
GENIUS!
Glad to be of help