限制“自定义帖子”类型中的摘录长度,并删除括号

时间:2019-02-22 06:34:06

标签: wordpress custom-post-type

我正在尝试将自定义帖子的摘录长度限制为100个字符,并删除句子结尾的括号。我已经尝试了Stack Overflow上列出的各种解决方案,但到目前为止没有任何效果。

我有4种自定义帖子类型:排毒,食谱,运动,生活方式

Post Feed Screenshot

1 个答案:

答案 0 :(得分:0)

请使用以下代码删除括号。

function remove_excerpt_more( $more ) {
    return '';
}
add_filter('excerpt_more', 'remove_excerpt_more');

,并使用下面的代码限制摘录的长度。

function custom_excerpt_length( $length ) {
global $post;
if ($post->post_type == 'post')
  return 25;
else if ($post->post_type == 'custom_post_type')
  return 15;
else
  return 25;
}
   return 20;
}
add_filter( 'excerpt_length', 'custom_excerpt_length', 999 );