2016-05-29 77 views
0

我在wordpress themefunction.php写了这个代码:添加功能,以特定的WordPress页面

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?

谢谢

回答

1

那么你可以使用is_page(),并通过页塞为同一..你可以通过页塞,标题,在这个函数

例1d什么如果你的ID是 - 然后使用is_page( '5580')

但the_excerpt主要是我们ED的博客,所以,如果你正在寻找博客,然后用is_home()为同一

请参考下链接查看更多细节 - https://developer.wordpress.org/reference/functions/is_page/

0

像这样:

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); 
} 
相关问题