将函数添加到特定的WordPress页面

将函数添加到特定的WordPress页面,wordpress,Wordpress,我在我的wordpress主题的function.php中编写了这段代码: 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_ex

我在我的
wordpress主题的
function.php
中编写了这段代码:

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 );
如何仅为特定的WordPress页面加载此代码,特别是页面id 5580


谢谢

您可以使用is_page()并传递页面slug。您可以在此函数中传递页面slug、title、Id任何内容

例如,如果您的id为-5580,则使用is\u页面('5580')

但是这段摘录主要用于博客,所以如果你正在寻找博客,那么就使用is\u home()


有关更多详细信息,请参阅下面的链接-

您可以使用is_page()并传递页面slug。您可以传递页面slug、title、Id此函数中的任何内容

例如,如果您的id为-5580,则使用is\u页面('5580')

但是这段摘录主要用于博客,所以如果你正在寻找博客,那么就使用is\u home()

有关更多详细信息,请参阅下面的链接-

,如下图所示:

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 );
}
像这样:

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