[英]excerpt length in Child Theme
Once again my amature php skills have me pinned down by its strings! 再一次,我精通的php技能让我被它的字符串所束缚!
I am trying to change the excerpt length of the post summaries on my Wordpress blog page. 我正在尝试更改Wordpress博客页面上帖子摘要的摘录长度。 So far I have created a child theme, replaces the content.php file code to 到目前为止,我已经创建了一个子主题,将content.php文件代码替换为
<div class="entry-content">
<?php the_excerpt( __( 'Continue reading <span class="meta-nav">→</span>', 'twentyeleven' ) ); ?>
<?php wp_link_pages( array( 'before' => '<div class="page-link"><span>' . __( 'Pages:', 'twentyeleven' ) . '</span>', 'after' => '</div>' ) ); ?>
</div><!-- .entry-content -->
and added a functions file with the following code 并使用以下代码添加了功能文件
<?php
function CHILDTHEME_excerpt_length($length) {
return 600;
}
add_filter('excerpt_length', 'CHILDTHEME_excerpt_length'); ?>
AND what do you know...... It still remains the same length of summary on the blog page as before. 以及您知道什么……博客页面上的摘要长度仍然和以前一样。 What am I doing wrong? 我究竟做错了什么?
All help is very much appreciated as always 一如既往地感谢所有帮助
You must set the filter priority right: 您必须正确设置过滤器优先级:
add_filter('excerpt_length', 'CHILDTHEME_excerpt_length', 999);
Without specifying the priority WordPress filter on this function will run last and override what you set here. 如果不指定此功能的优先级,WordPress过滤器将最后运行并覆盖您在此处设置的内容。
You probably have a filter that is running after yours and resetting the length. 您可能有一个过滤器在您的过滤器之后运行并重置长度。 You can set a higher priority, this can be guesswork until you get it high enough. 您可以设置更高的优先级,这可能是猜测,直到您将其设置得足够高为止。 Another option is to remove all the existing filters for this hook before you add yours: 另一种选择是在添加钩子之前,删除该钩子的所有现有过滤器:
function my_excerpt_length($length){
return 400;
}
remove_all_filters( 'excerpt_length' );
add_filter( 'excerpt_length', 'my_excerpt_length', 999 );
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.