- This topic has 15 replies, 5 voices, and was last updated 4 years, 11 months ago by Leo.
-
AuthorPosts
-
April 19, 2017 at 9:48 am #307760Susanne
Hi Tom, Using GP deluxe again for another site I am working on. I have to tell you this theme is the most beautiful thing to work with and I love the documentation too. Thank you for this amazing work!
I have created a child theme and a custom post type (portfolio) and made the portfolio archive use 3 columns while the blog has one. So far so good.
Now I want the portfolio archive to show an excerpt length of 20 words, while the blog has an excerpt of 40. I could not find the filter/function for that anywhere, but i know it is doable. The customize settings affect the blog only. What would the filter for my portfolio excerpt be?
Thanks in advance!
April 19, 2017 at 2:23 pm #307903JamalHi Susanne
Please take a look at this topic https://isabelcastillo.com/different-excerpt-length-for-different-post-types. If that doesn’t work for you maybe this topic can shed some light https://generatepress.com/forums/topic/excerpt-length-in-elementor/#post-285109
Hope you get something working and share you code.
April 19, 2017 at 8:03 pm #307993TomLead DeveloperLead DeveloperThat first link is perfect, Jamal π
April 19, 2017 at 9:22 pm #308021SusanneThank you both, Jamal and Tom. Perfect!
First class service as usual.April 20, 2017 at 9:30 am #308188Susanne… actually it looks perfect, but it does not work. Maybe it interferes with the preferences set by the blog plugin? But I need those.. any idea why it would not work? I added the script like so to my functions in the child theme:
function isacustom_excerpt_length($length) { global $post; if ($post->post_type == 'post') return 25; else if ($post->post_type == 'portfolio') return 15; else return 25; } add_filter('excerpt_length', 'isacustom_excerpt_length');
April 20, 2017 at 10:11 am #308218TomLead DeveloperLead DeveloperCan you try replacing:
add_filter('excerpt_length', 'isacustom_excerpt_length');
With:
add_filter('excerpt_length', 'isacustom_excerpt_length', 100);
April 20, 2017 at 10:45 am #308229SusanneBrilliant! That did it. very exciting. Thanks so much Tom!
April 20, 2017 at 10:55 am #308232TomLead DeveloperLead DeveloperYou’re welcome π
May 9, 2019 at 6:56 am #894172HenryHow would I make this zero? I guess by adding ‘0’?
I have exactly the same question but in my example, I’d like to remove the excerpt completely.
Thanks!
// CHANGE EXCERPT LENGTH FOR DIFFERENT POST TYPES function isacustom_excerpt_length($length) { global $post; if ($post->post_type == ' CUSTOM POST TYPE') return 0; else if ($post->post_type == 'products') return 65; else if ($post->post_type == 'testimonial') return 75; else return 80; } add_filter('excerpt_length', 'isacustom_excerpt_length');
May 9, 2019 at 9:08 am #894340LeoStaffCustomer SupportYup 0 should work: https://docs.generatepress.com/article/excerpt_length/#examples
Have you tried it and it’s not working?
May 9, 2019 at 9:49 pm #894821HenryAlas, this didn’t work. Is is because the syntax is incorrect for my purpose? I am referring to Custom Taxonomy – i.e, categories so perhaps the syntax needs to be tweaked to reflect that?
Thanks for all help!!!
May 10, 2019 at 5:31 am #895138HenryHere is an update!
OK – the functions on this page didn’t work for me.
Just to re-clarify – what I am trying to do is REMOVE the excerpts from a Custom Taxonomy Category class I built using Pods.
I discovered this GP Hook which looks ideal to solve my problem:
add_filter( 'excerpt_length','lh_custom_category_excerpt_length', 1000 ); function lh_custom_category_excerpt_length( $length ) { if ( is_category() ) { return 0; } return $length; }
Now, I am using custom taxonomy so I thought I could change the above to this:
if ( is_tax('CUSTOM-NAME') )
Alas, no joy.
Then that got me thinking that the error lies here:
lh_custom_category_excerpt_length
^ That contains ‘category’ which I think might be wrong because I am trying to remove excerpts from custom taxonomy?
Does anyone have any ideas?
Thanks!!!
May 10, 2019 at 5:35 am #895141HenryUPDATE
I got it working! π
This worked for me:
add_filter( 'excerpt_length','lh_custom_taxonomy_excerpt_length', 1000 ); function lh_custom_taxonomy_excerpt_length( $length ) { if ( is_tax('country') ) { return 0; } return $length; }
Does anyone see any issue with this?
May 10, 2019 at 7:50 am #895400LeoStaffCustomer SupportLooks good to me π
The function name doesn’t matter. They just need to match.
It could be anything like
add_filter( 'excerpt_length','henry_is_cool', 1000 ); function henry_is_cool( $length ) { if ( is_tax('country') ) { return 0; } return $length; }
Glad you figured out!
May 10, 2019 at 4:21 pm #895776HenryAmazing support as ever. Thanks – solved it.
-
AuthorPosts
- You must be logged in to reply to this topic.