[Resolved] disable excerpt custom post type

Home Forums Support [Resolved] disable excerpt custom post type

Home Forums Support disable excerpt custom post type

Viewing 14 posts - 1 through 14 (of 14 total)
  • Author
    Posts
  • #2146522
    Daniele

    Hello,
    how can I disable excerpt on custom post type archives?

    Is there also a way to show categories under the posts?

    thank you

    #2146569
    David
    Staff
    Customer Support

    Hi there,

    the easiest method is to use a Block Element – Content Template:

    https://docs.generatepress.com/article/block-element-content-template/

    #2146945
    Daniele

    Hi David,
    I prefer not installing generateblocks, I aiming to maximum speed in this website.
    Is there any filter I could use?

    #2146959
    David
    Staff
    Customer Support

    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/

    #2146972
    Daniele

    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?

    #2146977
    David
    Staff
    Customer Support

    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;
    }
    #2146985
    Daniele

    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;
    }
    
    #2146995
    David
    Staff
    Customer Support

    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.

    #2147007
    Daniele

    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

    #2147018
    David
    Staff
    Customer Support

    You need to use this option for the read more:

    $options[‘read_more’]

    Is the other meta for the archives or the single post ?

    #2147019
    Daniele

    I am on the archive, this is the page: https://dev1.oceandigitals.com/portfolio/

    #2147140
    Ying
    Staff
    Customer Support

    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;
    } );
    #2147682
    Daniele

    Perfect, it is working now!

    #2148543
    Ying
    Staff
    Customer Support

    Glad to hear that 🙂

Viewing 14 posts - 1 through 14 (of 14 total)
  • You must be logged in to reply to this topic.