Archived topic
disable excerpt custom post type
13 replies · Started by Daniele on March 8, 2022
Hello,
how can I disable excerpt on custom post type archives?
Is there also a way to show categories under the posts?
thank you
Hi there,
the easiest method is to use a Block Element - Content Template:
https://docs.generatepress.com/article/block-element-content-template/
Hi David,
I prefer not installing generateblocks, I aiming to maximum speed in this website.
Is there any filter I could use?
Of course we have filters :) Just a note though GB won't affect your sites performance as it simply outputs the necessary HTML and CSS required :)
Remove the excerpt by settings length to 0 with this filter:
https://docs.generatepress.com/article/excerpt_length/#examples
Example of applying that to a specific CPT:
function db_cpt_excerpt_zero($length) {
global $post;
if ($post->post_type == 'your-post-type') {
$length = 0;
}
return $length;
}
add_filter('excerpt_length', 'db_cpt_excerpt_zero', 100);
And this to add meta to your post type:
https://docs.generatepress.com/article/generate_entry_meta_post_types/
Thanks,
for the read more button? I have to remove it with css?
For the meta now I see only data and author, but I'm interested in categories
Regarding the plugin, it does not load any extra CSS or JS?
You can use the option_generate_blog_settings filter to effectively change any blog setting for a specific condition:
https://docs.generatepress.com/article/option_generate_blog_settings/
eg.
add_filter( 'option_generate_blog_settings', 'lh_custom_search_results_page_settings' );
function lh_custom_search_results_page_settings( $options ) {
if ($post->post_type == 'your-post-type') {
$options['read_more_button'] = false;
}
return $options;
}
mmm..is not working with this:
add_filter( 'option_generate_blog_settings', 'lh_custom_search_results_page_settings' );
function lh_custom_search_results_page_settings( $options ) {
if ($post->post_type == 'progetti') {
$options['read_more_button'] = false;
$options['date'] = false;
}
return $options;
}
Try this method instead:
add_filter( 'option_generate_blog_settings', 'lh_custom_search_results_page_settings' );
function lh_custom_search_results_page_settings( $options ) {
if ( 'progetti' === get_post_type() && ! is_singular() ) {
$options['read_more_button'] = false;
$options['date'] = false;
}
return $options;
}
If you can make sure the progetti name i added is correct.
With this:
add_filter( 'option_generate_blog_settings', 'lh_custom_search_results_page_settings' );
function lh_custom_search_results_page_settings( $options ) {
if ( 'progetti' === get_post_type() && ! is_singular() ) {
$options['read_more_button'] = false;
$options['date'] = false;
$options['categories'] = true;
$options['author'] = false;
}
return $options;
}
read more buttons is still present, and Catagories are not visible
date and author works fine
You need to use this option for the read more:
$options[‘read_more’]
Is the other meta for the archives or the single post ?
I am on the archive, this is the page: https://dev1.oceandigitals.com/portfolio/
Hi Daniel,
I'm not seeing read-more/date/author on your archive page:
https://www.screencast.com/t/onqvDgmCg9a
For the categories, add this PHP snippet to activate the footer meta for your custom post type:
add_filter( 'generate_footer_meta_post_types', function( $types ) {
$types[] = 'progetti';
return $types;
} );
Perfect, it is working now!
Glad to hear that :)