Php Wordpress从摘录中删除阅读更多内容

Php Wordpress从摘录中删除阅读更多内容,php,wordpress,Php,Wordpress,我对Remove_filter()有问题。Remove filter可以工作,但不能100%,它不会从Read More中删除前3个点,也不会替换父摘录 更清楚地说,我想做的是删除阅读更多内容,并将其更改为[…] 我希望从子主题执行此操作 下面是截图示例和示例 父主题函数.php代码 function new_excerpt_more($more) { global $post; return '… <a href="'. get_permalink($post-&

我对Remove_filter()有问题。Remove filter可以工作,但不能100%,它不会从Read More中删除前3个点,也不会替换父摘录

更清楚地说,我想做的是删除阅读更多内容,并将其更改为[…]

我希望从子主题执行此操作

下面是截图示例和示例

父主题函数.php代码

    function new_excerpt_more($more) {
    global $post;
    return '… <a href="'. get_permalink($post->ID) . '">' . 'Read More!   &raquo;'     . '</a>';
   }
    add_filter('excerpt_more', 'new_excerpt_more');
函数新建\u摘录\u更多($更多){
全球$员额;
返回“…”;
}
添加过滤器(“摘录更多”、“新摘录更多”);
子主题函数.php代码

       function child_theme_setup() {
       // override parent theme's 'more' text for excerpts
       remove_filter( 'excerpt_more', 'new_excerpt_more' ); 

      }
     add_action( 'after_setup_theme', 'child_theme_setup' );
    // Replaces the excerpt "Read More" text by a link
     function new_excerpt($more) {
     global $post;
     return '<a class="moretag" href="'. get_permalink($post->ID) . '">[...]                      </a>';
      }
      add_filter('excerpt', 'new_excerpt');
函数子主题设置(){
//为摘录覆盖父主题的“更多”文本
删除过滤器(“摘录更多”、“新建摘录更多”);
}
添加动作('after_setup_theme'、'child_theme_setup');
//用链接替换摘录的“阅读更多”文本
新函数摘录($more){
全球$员额;
返回“”;
}
添加过滤器(“摘录”、“新摘录”);

您只需要稍微更新一下代码

// Changing excerpt more
function new_excerpt_more($more) {
  global $post;
  remove_filter('excerpt_more', 'new_excerpt_more'); 
  return ' <a class="read_more" href="'. get_permalink($post->ID) . '">' . ' do whatever you want to update' . '</a>';
}
add_filter('excerpt_more','new_excerpt_more',11);
//更改摘录更多信息
函数新摘录更多($更多){
全球$员额;
删除过滤器(“摘录更多”、“新摘录更多”);
返回“”;
}
添加过滤器(“摘录更多”,“新摘录更多”,11);

钩子的默认优先级为10。父主题的钩子可能是第二个添加的,这意味着钩子和父钩子具有相同的优先级,但父主题的钩子是最后一个,因此它不反映更改。

如果您不想编写新函数,只希望它在特定区域工作,您也可以尝试wp_trim_words()函数与获取内容()结合使用

例如:

<?php echo wp_trim_words(get_the_content(), 60) ?>


上面所做的是将从get_the_content()返回的任何内容的字数缩减到您想要的字数(在本例中为60)。

清楚地指定您的问题。@HappyCoding,我编辑了它。它仍然是一样的,3个点仍然保留。我在那里写的不会改变。将挂钩优先级更新为11。。然后检查结果