增加Schema Wordpress主题的摘录长度

时间:2016-06-28 06:58:57

标签: wordpress schema

我努力让摘录的长度至少达到250个单词,但它仍然停留在50个单词上。我尝试更改阅读设置,即使在自定义PHP编辑。 我在functions.php中添加了以下代码

function excerpt($limit) {
    $excerpt = explode(' ', get_the_excerpt(), $limit);
    if (count($excerpt)>=$limit) {
       array_pop($excerpt);
       $excerpt = implode(" ",$excerpt).'...';
    } else {
       $excerpt = implode(" ",$excerpt);
    }   
    $excerpt = preg_replace('`[[^]]*]`','',$excerpt);
    return $excerpt;
}

function content($limit) {
  $content = explode(' ', get_the_content(), $limit);
  if (count($content)>=$limit) {
    array_pop($content);
    $content = implode(" ",$content).'...';
  } else {
    $content = implode(" ",$content);
  } 
  $content = preg_replace('/[.+]/','', $content);
  $content = apply_filters('the_content', $content); 
  $content = str_replace(']]>', ']]>', $content);
  return $content;
}`

如果你想看的话,这是homepage

1 个答案:

答案 0 :(得分:0)

$excerpt = get_the_excerpt();
echo string_limit_words($excerpt,250);

其中250是单词数