Site logo

Archived topic

custom excerpt length for custom post type

15 replies · Started by Susanne on April 19, 2017

Viewing posts 1–15 of 16

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!

That first link is perfect, Jamal :)

Thank you both, Jamal and Tom. Perfect!
First class service as usual.

... 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');

Can you try replacing:

add_filter('excerpt_length', 'isacustom_excerpt_length');

With:

add_filter('excerpt_length', 'isacustom_excerpt_length', 100);

Brilliant! That did it. very exciting. Thanks so much Tom!

You're welcome :)

How 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');

Alas, 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!!!

Here 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!!!

UPDATE

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?

Looks 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!

Amazing support as ever. Thanks - solved it.

This archived topic is closed to new replies.