0

I wrote this code in function.php of my wordpress theme:

remove_filter('get_the_excerpt', 'wp_trim_excerpt');
add_filter('get_the_excerpt', 'wpse_custom_wp_trim_excerpt');
function wpse_excerpt_length( $length ) {
    return 40;
}
add_filter( 'excerpt_length', 'wpse_excerpt_length', 999 );

How can I load this code only for a specific WordPress page, in particular page-id 5580?

Thank you

2 Answers 2

1

Like this:

if( is_page( 5580 ) {
    remove_filter('get_the_excerpt', 'wp_trim_excerpt');
    add_filter('get_the_excerpt', 'wpse_custom_wp_trim_excerpt');
    function wpse_excerpt_length( $length ) {
        return 40;
    }

    add_filter( 'excerpt_length', 'wpse_excerpt_length', 999 );
}
Sign up to request clarification or add additional context in comments.

Comments

0

Well you can use is_page() and pass page slug for the same ..you can pass page slug , title , Id anything in this function

Example if your id is - 5580 then use is_page('5580')

but the_excerpt is mostly used for blog so if you are looking for blog then use is_home() for the same

Refer below link for more details - https://developer.wordpress.org/reference/functions/is_page/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.