WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] How To change Excerpt Length Depending on the page (4 posts)

  1. keyaspects
    Member
    Posted 3 years ago #

    I have some code displaying excerpts in the side bar - I want the snippet of the post to be a different length to that displayed when you go to the events category page.

    I have this so far in my functions.php file but it doesn't work.

    function custom_excerpt_length($length) {
        if (is_page('Events')) {  //For the events page
            return 65;
        } else {
            return 40; //for all others pages
        }
    }
    add_filter('excerpt_length', 'custom_excerpt_length');

    "Allowed markup: a blockquote code em strong ul ol li.
    Put code in between backticks."

  2. keesiemeijer
    moderator
    Posted 3 years ago #

    Have you tried with the is_category() conditional tag.

  3. keyaspects
    Member
    Posted 3 years ago #

    Hi keesie
    Yes but this will change the length based on the category.
    I only have one category so this won't really do anything for me.

    I need to change the length displayed in my sidebar to 40 words (sidebar is only displayed on the home page). Hence, is_page()
    Then when I view the Events Category page, the excerpt length will be longer. (65)

  4. keesiemeijer
    moderator
    Posted 3 years ago #

Topic Closed

This topic has been closed to new replies.

About this Topic