user3718303
user3718303

Reputation: 39

Add function to specific WordPress page

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

Upvotes: 0

Views: 1340

Answers (2)

Steve Clason
Steve Clason

Reputation: 301

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 );
}

Upvotes: 1

Manthan Dave
Manthan Dave

Reputation: 2157

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/

Upvotes: 0

Related Questions